1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef DFX_MUSL_LOG_H 16 #define DFX_MUSL_LOG_H 17 18 #include <inttypes.h> 19 #include <stdarg.h> 20 #include <stddef.h> 21 22 #include "dfx_log_define.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #ifdef ENABLE_SIGHAND_MUSL_LOG 29 30 /* Log type */ 31 typedef enum { 32 /* min log type */ 33 LOG_TYPE_MIN = 0, 34 /* Used by app log. */ 35 LOG_APP = 0, 36 /* Log to kmsg, only used by init phase. */ 37 LOG_INIT = 1, 38 /* Used by core service, framework. */ 39 LOG_CORE = 3, 40 /* Used by kmsg log. */ 41 LOG_KMSG = 4, 42 /* max log type */ 43 LOG_TYPE_MAX 44 } LogType; 45 46 /* Log level */ 47 typedef enum { 48 /* min log level */ 49 LOG_LEVEL_MIN = 0, 50 /* Designates lower priority log. */ 51 LOG_DEBUG = 3, 52 /* Designates useful information. */ 53 LOG_INFO = 4, 54 /* Designates hazardous situations. */ 55 LOG_WARN = 5, 56 /* Designates very serious errors. */ 57 LOG_ERROR = 6, 58 /* Designates major fatal anomaly. */ 59 LOG_FATAL = 7, 60 /* max log level */ 61 LOG_LEVEL_MAX, 62 } LogLevel; 63 64 extern int HiLogAdapterPrintArgs( 65 const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *fmt, va_list ap); 66 extern int vsnprintfp_s(char *strDest, size_t destMax, size_t count, int priv, const char *format, va_list arglist); 67 68 __attribute__ ((visibility("hidden"))) int MuslHiLogPrinter( 69 LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...); 70 71 __attribute__ ((visibility("hidden"))) int DfxLogPrint( 72 const LogLevel logLevel, const unsigned int domain, const char* tag, const char *fmt, ...); 73 74 #define DFXLOG_PRINT(prio, ...) DfxLogPrint(prio, LOG_DOMAIN, LOG_TAG, ##__VA_ARGS__) 75 76 #define DFXLOG_DEBUG(...) DFXLOG_PRINT(LOG_DEBUG, ##__VA_ARGS__) 77 #define DFXLOG_INFO(...) DFXLOG_PRINT(LOG_INFO, ##__VA_ARGS__) 78 #define DFXLOG_WARN(...) DFXLOG_PRINT(LOG_WARN, ##__VA_ARGS__) 79 #define DFXLOG_ERROR(...) DFXLOG_PRINT(LOG_ERROR, ##__VA_ARGS__) 80 #define DFXLOG_FATAL(...) DFXLOG_PRINT(LOG_FATAL, ##__VA_ARGS__) 81 82 #else 83 84 #define DFXLOG_PRINT(prio, ...) 85 86 #define DFXLOG_DEBUG(...) 87 #define DFXLOG_INFO(...) 88 #define DFXLOG_WARN(...) 89 #define DFXLOG_ERROR(...) 90 #define DFXLOG_FATAL(...) 91 #endif 92 93 #ifdef __cplusplus 94 } 95 #endif 96 #endif