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 UDMF_LOGGER_H
17 #define UDMF_LOGGER_H
18 #include <memory>
19
20 #include "hilog/log.h"
21
22 namespace OHOS {
23 namespace UDMF {
24 // param of log interface, such as UDMF_LABEL.
25 enum UdmfSubModule {
26 UDMF_FRAMEWORK = 0, // for framework core module
27 UDMF_KITS_INNER, // for udmf innerkits module
28 UDMF_KITS_NAPI, // for udmf napi kits module
29 UDMF_CLIENT, // for udmf client module
30 UDMF_SERVICE, // for udmf service module
31 UDMF_CAPI, // for udmf capi module
32 UDMF_TEST, // for udmf test module
33 };
34
35 // 0xD001600: subsystem:distributeddatamgr module:udmf, 8 bits reserved.
LogLabel()36 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
37 {
38 return { LOG_CORE, 0xD001656, "UDMF" };
39 }
40
41 // In order to improve performance, do not check the module range.
42 // Besides, make sure module is less than UDMF_SERVICE.
43 #define LOG_FATAL(module, fmt, ...) \
44 do { \
45 auto lable = LogLabel(); \
46 if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) { \
47 break; \
48 } \
49 ((void)HILOG_IMPL(lable.type, LogLevel::LOG_FATAL, lable.domain, lable.tag, \
50 LOG_TAG ":%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
51 } while (0)
52
53 #define LOG_ERROR(module, fmt, ...) \
54 do { \
55 auto lable = LogLabel(); \
56 if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) { \
57 break; \
58 } \
59 ((void)HILOG_IMPL(lable.type, LogLevel::LOG_ERROR, lable.domain, lable.tag, \
60 LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
61 } while (0)
62
63 #define LOG_WARN(module, fmt, ...) \
64 do { \
65 auto lable = LogLabel(); \
66 if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) { \
67 break; \
68 } \
69 ((void)HILOG_IMPL(lable.type, LogLevel::LOG_WARN, lable.domain, lable.tag, \
70 LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
71 } while (0)
72
73 #define LOG_INFO(module, fmt, ...) \
74 do { \
75 auto lable = LogLabel(); \
76 if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) { \
77 break; \
78 } \
79 ((void)HILOG_IMPL(lable.type, LogLevel::LOG_INFO, lable.domain, lable.tag, \
80 LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
81 } while (0)
82
83 #define LOG_DEBUG(module, fmt, ...) \
84 do { \
85 auto lable = LogLabel(); \
86 if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) { \
87 break; \
88 } \
89 ((void)HILOG_IMPL(lable.type, LogLevel::LOG_DEBUG, lable.domain, lable.tag, \
90 LOG_TAG "::%{public}s " fmt, __FUNCTION__, ##__VA_ARGS__)); \
91 } while (0)
92 } // namespace UDMF
93 } // namespace OHOS
94 #endif // UDMF_LOGGER_H
95