1 /* 2 * Copyright (c) 2021 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 16 #ifndef HIVIEWDFX_HILOG_BASE_C_H 17 #define HIVIEWDFX_HILOG_BASE_C_H 18 19 #include <stdarg.h> 20 #include <stdbool.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * Log domain, indicates the log service domainID. Different LogType have different domainID ranges. 28 * Log type of LOG_APP: 0-0xFFFF 29 * Log type of LOG_CORE & LOG_INIT: 0xD000000-0xD0FFFFF 30 */ 31 #ifndef LOG_DOMAIN 32 #define LOG_DOMAIN 0 33 #endif 34 35 /** 36 * Log tag, indicates the log service tag, you can customize the tag as needed, usually the keyword of the module. 37 */ 38 #ifndef LOG_TAG 39 #define LOG_TAG NULL 40 #endif 41 42 /* Log type */ 43 typedef enum { 44 /* min log type */ 45 LOG_TYPE_MIN = 0, 46 /* Used by app log. */ 47 LOG_APP = 0, 48 /* Log to kmsg, only used by init phase. */ 49 LOG_INIT = 1, 50 /* Used by core service, framework. */ 51 LOG_CORE = 3, 52 /* Used by kmsg log. */ 53 LOG_KMSG = 4, 54 /* max log type */ 55 LOG_TYPE_MAX 56 } LogType; 57 58 /* Log level */ 59 typedef enum { 60 /* min log level */ 61 LOG_LEVEL_MIN = 0, 62 /* Designates lower priority log. */ 63 LOG_DEBUG = 3, 64 /* Designates useful information. */ 65 LOG_INFO = 4, 66 /* Designates hazardous situations. */ 67 LOG_WARN = 5, 68 /* Designates very serious errors. */ 69 LOG_ERROR = 6, 70 /* Designates major fatal anomaly. */ 71 LOG_FATAL = 7, 72 /* max log level */ 73 LOG_LEVEL_MAX, 74 } LogLevel; 75 76 int HiLogBasePrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) 77 __attribute__((__format__(os_log, 5, 6))); 78 79 /** 80 * @brief Hilog base interface of different log level. 81 * DEBUG: Designates lower priority log. 82 * INFO: Designates useful information. 83 * WARN: Designates hazardous situations. 84 * ERROR: Designates very serious errors. 85 * FATAL: Designates major fatal anomaly. 86 * 87 * @param type enum:LogType 88 */ 89 #define HILOG_BASE_DEBUG(type, ...) ((void)HiLogBasePrint((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 90 91 #define HILOG_BASE_INFO(type, ...) ((void)HiLogBasePrint((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 92 93 #define HILOG_BASE_WARN(type, ...) ((void)HiLogBasePrint((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 94 95 #define HILOG_BASE_ERROR(type, ...) ((void)HiLogBasePrint((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 96 97 #define HILOG_BASE_FATAL(type, ...) ((void)HiLogBasePrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 98 99 /** 100 * @brief Check whether log of a specified domain, tag and level can be printed. 101 * 102 * @param domain macro:LOG_DOMAIN 103 * @param tag macro:LOG_TAG 104 * @param level enum:LogLevel 105 */ 106 bool HiLogBaseIsLoggable(unsigned int domain, const char *tag, LogLevel level); 107 108 #ifdef __cplusplus 109 } 110 #endif 111 112 #ifdef HILOG_RAWFORMAT 113 #include "hilog_base/log_base_inner.h" 114 #endif 115 116 #endif // HIVIEWDFX_HILOG_BASE_C_H 117