• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DFX_LOG_H
16 #define DFX_LOG_H
17 
18 #ifndef DFX_NO_PRINT_LOG
19 #include <sys/types.h>
20 #ifdef DFX_LOG_USE_HILOG_BASE
21 #include <hilog_base/log_base.h>
22 #else
23 #include <hilog/log.h>
24 #endif
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #ifdef DFX_NO_PRINT_LOG
32 #define DfxLogDebug(fmt, ...)
33 #define DfxLogInfo(fmt, ...)
34 #define DfxLogWarn(fmt, ...)
35 #define DfxLogError(fmt, ...)
36 #define DfxLogFatal(fmt, ...)
37 
38 #define LOGD(fmt, ...)
39 #define LOGI(fmt, ...)
40 #define LOGW(fmt, ...)
41 #define LOGE(fmt, ...)
42 #define LOGF(fmt, ...)
43 
44 #else
45 
46 #define FILE_NAME   (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__))
47 
48 #ifdef LOG_DOMAIN
49 #undef LOG_DOMAIN
50 #define LOG_DOMAIN 0xD002D11
51 #endif
52 
53 #ifdef LOG_TAG
54 #undef LOG_TAG
55 #define LOG_TAG "DfxFaultLogger"
56 #endif
57 
58 typedef enum Level {
59     DEBUG = 0,
60     INFO,
61     WARN,
62     ERROR,
63     FATAL
64 } Level;
65 
66 bool CheckDebugLevel(void);
67 void InitDebugFd(int32_t fd);
68 int DfxLog(const Level logLevel, const unsigned int domain, const char* tag, const char *fmt, ...);
69 
70 #define DfxLogDebug(fmt, ...)   DfxLog(DEBUG, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
71 #define DfxLogInfo(fmt, ...)    DfxLog(INFO, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
72 #define DfxLogWarn(fmt, ...)    DfxLog(WARN, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
73 #define DfxLogError(fmt, ...)   DfxLog(ERROR, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
74 #define DfxLogFatal(fmt, ...)   DfxLog(FATAL, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__)
75 
76 #define LOGD(fmt, ...) DfxLog(DEBUG, LOG_DOMAIN, LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
77 #define LOGI(fmt, ...) DfxLog(INFO, LOG_DOMAIN, LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
78 #define LOGW(fmt, ...) DfxLog(WARN, LOG_DOMAIN, LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
79 #define LOGE(fmt, ...) DfxLog(ERROR, LOG_DOMAIN, LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
80 #define LOGF(fmt, ...) DfxLog(FATAL, LOG_DOMAIN, LOG_TAG, "[%s:%d]" fmt, (FILE_NAME), (__LINE__), ##__VA_ARGS__)
81 
82 #endif
83 #ifdef __cplusplus
84 }
85 #endif
86 #endif
87