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 RDB_LOGGER_H
17 #define RDB_LOGGER_H
18
19 #include "hilog/log.h"
20
21 namespace OHOS {
22 namespace Rdb {
LogLabel()23 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
24 {
25 return { LOG_CORE, 0xD001650, "Rdb" };
26 }
27 } // namespace Rdb
28
29 namespace RdbNdk {
LogLabel()30 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
31 {
32 return { LOG_CORE, 0xD001656, "RdbNdk" };
33 }
34 } // namespace RdbNdk
35
36 namespace SendableRdb {
LogLabel()37 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
38 {
39 return { LOG_CORE, 0xD001650, "SRdb" };
40 }
41 } // namespace Rdb
42
43 namespace GraphStoreJsKit {
LogLabel()44 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
45 {
46 return { LOG_CORE, 0xD001660, "GdbJS" };
47 }
48 } // namespace GraphStoreJsKit
49
50 namespace DistributedDataAip {
LogLabel()51 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
52 {
53 return { LOG_CORE, 0xD001660, "GdbNative" };
54 }
55 } // namespace DistributedDataAip
56 } // namespace OHOS
57
58 #define LOG_DEBUG(fmt, ...) \
59 do { \
60 auto lable = LogLabel(); \
61 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) { \
62 ((void)HILOG_IMPL(lable.type, LOG_DEBUG, lable.domain, lable.tag, \
63 LOG_TAG "[%{public}s]: " fmt, __FUNCTION__, ##__VA_ARGS__)); \
64 } \
65 } while (0)
66
67 #define LOG_INFO(fmt, ...) \
68 do { \
69 auto lable = LogLabel(); \
70 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) { \
71 ((void)HILOG_IMPL(lable.type, LOG_INFO, lable.domain, lable.tag, \
72 LOG_TAG "[%{public}s]: " fmt, __FUNCTION__, ##__VA_ARGS__)); \
73 } \
74 } while (0)
75
76 #define LOG_WARN(fmt, ...) \
77 do { \
78 auto lable = LogLabel(); \
79 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) { \
80 ((void)HILOG_IMPL(lable.type, LOG_WARN, lable.domain, lable.tag, \
81 LOG_TAG "[%{public}s]: " fmt, __FUNCTION__, ##__VA_ARGS__)); \
82 } \
83 } while (0)
84
85 #define LOG_ERROR(fmt, ...) \
86 do { \
87 auto lable = LogLabel(); \
88 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) { \
89 ((void)HILOG_IMPL(lable.type, LOG_ERROR, lable.domain, lable.tag, \
90 LOG_TAG "[%{public}s]: " fmt, __FUNCTION__, ##__VA_ARGS__)); \
91 } \
92 } while (0)
93
94 #define LOG_FATAL(fmt, ...) \
95 do { \
96 auto lable = LogLabel(); \
97 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) { \
98 ((void)HILOG_IMPL(lable.type, LOG_FATAL, lable.domain, lable.tag, \
99 LOG_TAG "[%{public}s]: " fmt, __FUNCTION__, ##__VA_ARGS__)); \
100 } \
101 } while (0)
102
103 #endif // RDB_LOGGER_H
104