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_C_H 17 #define HIVIEWDFX_HILOG_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_INIT = 1, 41 // Used by core service, framework. 42 LOG_CORE = 3, 43 LOG_KMSG = 4, 44 LOG_TYPE_MAX 45 } LogType; 46 47 // Log level 48 typedef enum { 49 LOG_LEVEL_MIN = 0, 50 LOG_DEBUG = 3, 51 LOG_INFO = 4, 52 LOG_WARN = 5, 53 LOG_ERROR = 6, 54 LOG_FATAL = 7, 55 LOG_LEVEL_MAX, 56 } LogLevel; 57 58 const char* GetLastFatalMessage(void); 59 60 int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) 61 __attribute__((__format__(os_log, 5, 6))); 62 63 #define HILOG_DEBUG(type, ...) ((void)HiLogPrint((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 64 65 #define HILOG_INFO(type, ...) ((void)HiLogPrint((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 66 67 #define HILOG_WARN(type, ...) ((void)HiLogPrint((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 68 69 #define HILOG_ERROR(type, ...) ((void)HiLogPrint((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 70 71 #define HILOG_FATAL(type, ...) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) 72 73 bool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level); 74 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif // HIVIEWDFX_HILOG_C_H 80