• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 DFX_LOG_H
17 #define DFX_LOG_H
18 
19 #ifndef DFX_NO_PRINT_LOG
20 #ifdef DFX_LOG_HILOG_BASE
21 #include <hilog_base/log_base.h>
22 #else
23 #include <hilog/log.h>
24 #endif
25 #include "dfx_log_define.h"
26 #endif
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #ifndef DFX_NO_PRINT_LOG
33 
34 #ifdef DFX_LOG_HILOG_BASE
35 #ifdef DFX_LOG_UNWIND
36 #define DFXLOGD(fmt, ...) HILOG_BASE_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__)
37 #else
38 #define DFXLOGD(fmt, ...)
39 #endif
40 #define DFXLOGI(fmt, ...) HILOG_BASE_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
41 #define DFXLOGW(fmt, ...) HILOG_BASE_WARN(LOG_CORE, fmt, ##__VA_ARGS__)
42 #define DFXLOGE(fmt, ...) HILOG_BASE_ERROR(LOG_CORE, fmt, ##__VA_ARGS__)
43 #define DFXLOGF(fmt, ...) \
44     HILOG_BASE_FATAL(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
45 
46 #ifdef DFX_LOG_UNWIND
47 #ifdef ALLOW_TO_STDERR
48 #define DFXLOGU(fmt, ...) \
49     HILOG_BASE_INFO(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__); \
50     fprintf(stderr, "%s\n", fmt)
51 #else
52 #define DFXLOGU(fmt, ...) \
53     HILOG_BASE_INFO(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
54 #endif
55 #else
56 #define DFXLOGU(fmt, ...)
57 #endif
58 
59 #else
60 
61 #define DFXLOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__)
62 #define DFXLOGI(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
63 #define DFXLOGW(fmt, ...) HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__)
64 #define DFXLOGE(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__)
65 #define DFXLOGF(fmt, ...) \
66     HILOG_FATAL(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
67 
68 #ifdef DFX_LOG_UNWIND
69 #define DFXLOGU(fmt, ...) \
70     HILOG_INFO(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
71 #else
72 #define DFXLOGU(fmt, ...)
73 #endif
74 
75 #endif
76 
77 #else
78 
79 #define DFXLOGD(fmt, ...)
80 #define DFXLOGI(fmt, ...)
81 #define DFXLOGW(fmt, ...)
82 #define DFXLOGE(fmt, ...)
83 #define DFXLOGF(fmt, ...)
84 #define DFXLOGU(fmt, ...)
85 #endif
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 #endif
91