1 /*
2  * Copyright (c) 2023 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 OHOS_FORM_FWK_FMS_LOG_WRAPPER_H
17 #define OHOS_FORM_FWK_FMS_LOG_WRAPPER_H
18 
19 #define CONFIG_HILOG
20 #ifdef CONFIG_HILOG
21 #include <cinttypes>
22 #include <functional>
23 
24 #include "hilog/log.h"
25 
26 #ifdef HILOG_FATAL
27 #undef HILOG_FATAL
28 #endif
29 
30 #ifdef HILOG_ERROR
31 #undef HILOG_ERROR
32 #endif
33 
34 #ifdef HILOG_WARN
35 #undef HILOG_WARN
36 #endif
37 
38 #ifdef HILOG_INFO
39 #undef HILOG_INFO
40 #endif
41 
42 #ifdef HILOG_BRIEF
43 #undef HILOG_BRIEF
44 #endif
45 
46 #ifdef HILOG_DEBUG
47 #undef HILOG_DEBUG
48 #endif
49 
50 #ifndef FMS_LOG_DOMAIN
51 #define FMS_LOG_DOMAIN 0xD001301
52 #endif
53 
54 #ifndef FMS_LOG_TAG
55 #define FMS_LOG_TAG "FormManagerService"
56 #endif
57 
58 #ifndef FMS_FUNC_FMT
59 #define FMS_FUNC_FMT "[%{public}s(%{public}s:%{public}d)]"
60 #endif
61 
62 #ifndef FMS_FUNC_FMT_BRIEF
63 #define FMS_FUNC_FMT_BRIEF "[%{public}s:%{public}d]"
64 #endif
65 
66 #ifndef FMS_FILE_NAME
67 #define FMS_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
68 #endif
69 
70 #ifndef FMS_FUNC_INFO
71 #define FMS_FUNC_INFO FMS_FILE_NAME, __FUNCTION__, __LINE__
72 #endif
73 
74 #ifndef FMS_FUNC_INFO_BRIEF
75 #define FMS_FUNC_INFO_BRIEF FMS_FILE_NAME, __LINE__
76 #endif
77 
78 #define HILOG_ERROR(fmt, ...) do { \
79     (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, FMS_LOG_DOMAIN, FMS_LOG_TAG, \
80     FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__);                   \
81 } while (0)
82 
83 #define HILOG_WARN(fmt, ...) do { \
84     (void)HILOG_IMPL(LOG_CORE, LOG_WARN, FMS_LOG_DOMAIN, FMS_LOG_TAG, \
85     FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__);                  \
86 } while (0)
87 
88 #define HILOG_INFO(fmt, ...) do { \
89     (void)HILOG_IMPL(LOG_CORE, LOG_INFO, FMS_LOG_DOMAIN, FMS_LOG_TAG, \
90     FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__);                  \
91 } while (0)
92 
93 #define HILOG_BRIEF(fmt, ...) do { \
94 (void)HILOG_IMPL(LOG_CORE, LOG_INFO, FMS_LOG_DOMAIN, FMS_LOG_TAG, \
95 FMS_FUNC_FMT_BRIEF fmt, FMS_FUNC_INFO_BRIEF, ##__VA_ARGS__);                  \
96 } while (0)
97 
98 #define HILOG_DEBUG(fmt, ...) do { \
99     (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, FMS_LOG_DOMAIN, FMS_LOG_TAG, \
100     FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__);                   \
101 } while (0)
102 
103 #define HILOG_FATAL(fmt, ...) do { \
104     (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, FMS_LOG_DOMAIN, FMS_LOG_TAG, \
105     FMS_FUNC_FMT fmt, FMS_FUNC_INFO, ##__VA_ARGS__);                   \
106 } while (0)
107 
108 #else
109 
110 #define HILOG_FATAL(...)
111 #define HILOG_ERROR(...)
112 #define HILOG_WARN(...)
113 #define HILOG_INFO(...)
114 #define HILOG_DEBUG(...)
115 
116 #endif  // CONFIG_HILOG
117 #endif  // OHOS_FORM_FWK_FMS_LOG_WRAPPER_H
118