1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License.
5800b99b8Sopenharmony_ci * You may obtain a copy of the License at
6800b99b8Sopenharmony_ci *
7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8800b99b8Sopenharmony_ci *
9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and
13800b99b8Sopenharmony_ci * limitations under the License.
14800b99b8Sopenharmony_ci */
15800b99b8Sopenharmony_ci
16800b99b8Sopenharmony_ci#ifndef DFX_LOG_H
17800b99b8Sopenharmony_ci#define DFX_LOG_H
18800b99b8Sopenharmony_ci
19800b99b8Sopenharmony_ci#ifndef DFX_NO_PRINT_LOG
20800b99b8Sopenharmony_ci#ifdef DFX_LOG_HILOG_BASE
21800b99b8Sopenharmony_ci#include <hilog_base/log_base.h>
22800b99b8Sopenharmony_ci#else
23800b99b8Sopenharmony_ci#include <hilog/log.h>
24800b99b8Sopenharmony_ci#endif
25800b99b8Sopenharmony_ci#include "dfx_log_define.h"
26800b99b8Sopenharmony_ci#endif
27800b99b8Sopenharmony_ci
28800b99b8Sopenharmony_ci#ifdef __cplusplus
29800b99b8Sopenharmony_ciextern "C" {
30800b99b8Sopenharmony_ci#endif
31800b99b8Sopenharmony_ci
32800b99b8Sopenharmony_ci#ifndef DFX_NO_PRINT_LOG
33800b99b8Sopenharmony_ci
34800b99b8Sopenharmony_ci#ifdef DFX_LOG_HILOG_BASE
35800b99b8Sopenharmony_ci// replace the old interface, and delete the old interface after the replacement is complete
36800b99b8Sopenharmony_ci#ifdef DFX_LOG_UNWIND
37800b99b8Sopenharmony_ci#define DFXLOGD(fmt, ...) HILOG_BASE_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__)
38800b99b8Sopenharmony_ci#else
39800b99b8Sopenharmony_ci#define DFXLOGD(fmt, ...)
40800b99b8Sopenharmony_ci#endif
41800b99b8Sopenharmony_ci#define DFXLOGI(fmt, ...) HILOG_BASE_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
42800b99b8Sopenharmony_ci#define DFXLOGW(fmt, ...) HILOG_BASE_WARN(LOG_CORE, fmt, ##__VA_ARGS__)
43800b99b8Sopenharmony_ci#define DFXLOGE(fmt, ...) HILOG_BASE_ERROR(LOG_CORE, fmt, ##__VA_ARGS__)
44800b99b8Sopenharmony_ci#define DFXLOGF(fmt, ...) \
45800b99b8Sopenharmony_ci    HILOG_BASE_FATAL(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
46800b99b8Sopenharmony_ci
47800b99b8Sopenharmony_ci#ifdef DFX_LOG_UNWIND
48800b99b8Sopenharmony_ci#ifdef ALLOW_TO_STDERR
49800b99b8Sopenharmony_ci#define DFXLOGU(fmt, ...) \
50800b99b8Sopenharmony_ci    HILOG_BASE_INFO(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__); \
51800b99b8Sopenharmony_ci    fprintf(stderr, "%s\n", fmt)
52800b99b8Sopenharmony_ci#else
53800b99b8Sopenharmony_ci#define DFXLOGU(fmt, ...) \
54800b99b8Sopenharmony_ci    HILOG_BASE_INFO(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
55800b99b8Sopenharmony_ci#endif
56800b99b8Sopenharmony_ci#else
57800b99b8Sopenharmony_ci#define DFXLOGU(fmt, ...)
58800b99b8Sopenharmony_ci#endif
59800b99b8Sopenharmony_ci
60800b99b8Sopenharmony_ci#else
61800b99b8Sopenharmony_ci// replace the old interface, and delete the old interface after the replacement is complete
62800b99b8Sopenharmony_ci#define DFXLOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__)
63800b99b8Sopenharmony_ci#define DFXLOGI(fmt, ...) HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
64800b99b8Sopenharmony_ci#define DFXLOGW(fmt, ...) HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__)
65800b99b8Sopenharmony_ci#define DFXLOGE(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__)
66800b99b8Sopenharmony_ci#define DFXLOGF(fmt, ...) \
67800b99b8Sopenharmony_ci    HILOG_FATAL(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
68800b99b8Sopenharmony_ci
69800b99b8Sopenharmony_ci#ifdef DFX_LOG_UNWIND
70800b99b8Sopenharmony_ci#define DFXLOGU(fmt, ...) \
71800b99b8Sopenharmony_ci    HILOG_INFO(LOG_CORE, "[%{public}s:%{public}d] " fmt, (__FILE_NAME__), (__LINE__), ##__VA_ARGS__)
72800b99b8Sopenharmony_ci#else
73800b99b8Sopenharmony_ci#define DFXLOGU(fmt, ...)
74800b99b8Sopenharmony_ci#endif
75800b99b8Sopenharmony_ci
76800b99b8Sopenharmony_ci#endif
77800b99b8Sopenharmony_ci
78800b99b8Sopenharmony_ci#else
79800b99b8Sopenharmony_ci
80800b99b8Sopenharmony_ci#define DFXLOGD(fmt, ...)
81800b99b8Sopenharmony_ci#define DFXLOGI(fmt, ...)
82800b99b8Sopenharmony_ci#define DFXLOGW(fmt, ...)
83800b99b8Sopenharmony_ci#define DFXLOGE(fmt, ...)
84800b99b8Sopenharmony_ci#define DFXLOGF(fmt, ...)
85800b99b8Sopenharmony_ci#define DFXLOGU(fmt, ...)
86800b99b8Sopenharmony_ci#endif
87800b99b8Sopenharmony_ci
88800b99b8Sopenharmony_ci#ifdef __cplusplus
89800b99b8Sopenharmony_ci}
90800b99b8Sopenharmony_ci#endif
91800b99b8Sopenharmony_ci#endif
92