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 // Log domain 27 #ifndef LOG_DOMAIN 28 #define LOG_DOMAIN 0 29 #endif 30 31 // Log tag 32 #ifndef LOG_TAG 33 #define LOG_TAG NULL 34 #endif 35 36 // Log type 37 typedef enum { 38 LOG_TYPE_MIN = 0, 39 LOG_APP = 0, 40 // Log to kmsg, only used by init phase. 41 LOG_INIT = 1, 42 // Used by core service, framework. 43 LOG_CORE = 3, 44 LOG_KMSG = 4, 45 LOG_TYPE_MAX 46 } LogType; 47 48 // Log level 49 typedef enum { 50 LOG_LEVEL_MIN = 0, 51 LOG_DEBUG = 3, 52 LOG_INFO = 4, 53 LOG_WARN = 5, 54 LOG_ERROR = 6, 55 LOG_FATAL = 7, 56 LOG_LEVEL_MAX, 57 } LogLevel; 58 59 int HiLogBasePrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) 60 __attribute__((__format__(os_log, 5, 6))); 61 62 #define HILOG_BASE_DEBUG(type, ...) ((void)HiLogBasePrint((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 63 64 #define HILOG_BASE_INFO(type, ...) ((void)HiLogBasePrint((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 65 66 #define HILOG_BASE_WARN(type, ...) ((void)HiLogBasePrint((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 67 68 #define HILOG_BASE_ERROR(type, ...) ((void)HiLogBasePrint((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 69 70 #define HILOG_BASE_FATAL(type, ...) ((void)HiLogBasePrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 71 72 bool HiLogBaseIsLoggable(unsigned int domain, const char *tag, LogLevel level); 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 #endif // HIVIEWDFX_HILOG_BASE_C_H 79