• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TEST,          // for udmf test module
32 };
33 
34 // 0xD001600: subsystem:distributeddatamgr module:udmf, 8 bits reserved.
LogLabel()35 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
36 {
37     return { LOG_CORE, 0xD001656, "UDMF" };
38 }
39 
40 // In order to improve performance, do not check the module range.
41 // Besides, make sure module is less than UDMF_SERVICE.
42 #define LOG_FATAL(module, fmt, ...)                                                                    \
43     do {                                                                                               \
44         using HiLog = OHOS::HiviewDFX::HiLog;                                                          \
45         auto lable = LogLabel();                                                                       \
46         if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) {                          \
47             break;                                                                                     \
48         }                                                                                              \
49         HiLog::Fatal(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \
50     } while (0)
51 
52 #define LOG_ERROR(module, fmt, ...)                                                                    \
53     do {                                                                                               \
54         using HiLog = OHOS::HiviewDFX::HiLog;                                                          \
55         auto lable = LogLabel();                                                                       \
56         if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) {                          \
57             break;                                                                                     \
58         }                                                                                              \
59         HiLog::Error(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \
60     } while (0)
61 
62 #define LOG_WARN(module, fmt, ...)                                                                     \
63     do {                                                                                               \
64         using HiLog = OHOS::HiviewDFX::HiLog;                                                          \
65         auto lable = LogLabel();                                                                       \
66         if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) {                           \
67             break;                                                                                     \
68         }                                                                                              \
69         HiLog::Warn(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__);  \
70     } while (0)
71 
72 #define LOG_INFO(module, fmt, ...)                                                                     \
73     do {                                                                                               \
74         using HiLog = OHOS::HiviewDFX::HiLog;                                                          \
75         auto lable = LogLabel();                                                                       \
76         if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) {                           \
77             break;                                                                                     \
78         }                                                                                              \
79         HiLog::Info(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__);  \
80     } while (0)
81 
82 #define LOG_DEBUG(module, fmt, ...)                                                                    \
83     do {                                                                                               \
84         using HiLog = OHOS::HiviewDFX::HiLog;                                                          \
85         auto lable = LogLabel();                                                                       \
86         if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) {                          \
87             break;                                                                                     \
88         }                                                                                              \
89         HiLog::Debug(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \
90     } while (0)
91 } // namespace UDMF
92 } // namespace OHOS
93 #endif // UDMF_LOGGER_H
94