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