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 /* Not print in release version. */ 55 LOG_ONLY_PRERELEASE = 5, 56 /* max log type */ 57 LOG_TYPE_MAX 58 } LogType; 59 60 /* Log level */ 61 typedef enum { 62 /* min log level */ 63 LOG_LEVEL_MIN = 0, 64 /* Designates lower priority log. */ 65 LOG_DEBUG = 3, 66 /* Designates useful information. */ 67 LOG_INFO = 4, 68 /* Designates hazardous situations. */ 69 LOG_WARN = 5, 70 /* Designates very serious errors. */ 71 LOG_ERROR = 6, 72 /* Designates major fatal anomaly. */ 73 LOG_FATAL = 7, 74 /* max log level */ 75 LOG_LEVEL_MAX, 76 } LogLevel; 77 78 int HiLogBasePrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) 79 __attribute__((__format__(os_log, 5, 6))); 80 81 /** 82 * @brief Hilog base interface of different log level. 83 * DEBUG: Designates lower priority log. 84 * INFO: Designates useful information. 85 * WARN: Designates hazardous situations. 86 * ERROR: Designates very serious errors. 87 * FATAL: Designates major fatal anomaly. 88 * 89 * @param type enum:LogType 90 */ 91 #define HILOG_BASE_DEBUG(type, ...) ((void)HiLogBasePrint((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 92 93 #define HILOG_BASE_INFO(type, ...) ((void)HiLogBasePrint((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 94 95 #define HILOG_BASE_WARN(type, ...) ((void)HiLogBasePrint((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 96 97 #define HILOG_BASE_ERROR(type, ...) ((void)HiLogBasePrint((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 98 99 #define HILOG_BASE_FATAL(type, ...) ((void)HiLogBasePrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 100 101 /** 102 * @brief Check whether log of a specified domain, tag and level can be printed. 103 * 104 * @param domain macro:LOG_DOMAIN 105 * @param tag macro:LOG_TAG 106 * @param level enum:LogLevel 107 */ 108 bool HiLogBaseIsLoggable(unsigned int domain, const char *tag, LogLevel level); 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #ifdef HILOG_RAWFORMAT 115 #include "hilog_base/log_base_inner.h" 116 #endif 117 118 #endif // HIVIEWDFX_HILOG_BASE_C_H 119