1 /*
2 * Copyright (c) 2021 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 DISTRIBUTEDDATA_LOG_PRINT_H
17 #define DISTRIBUTEDDATA_LOG_PRINT_H
18
19 #define OS_OHOS
20 #if defined OS_OHOS // log for OHOS
21
22 #include "hilog/log.h"
23 namespace OHOS {
24 namespace DistributedKv {
LogLabel()25 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
26 {
27 return { LOG_CORE, 0xD001610, "ZDDS" };
28 }
29 } // end namespace DistributesdKv
30
31 namespace DistributedData {
LogLabel()32 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
33 {
34 return { LOG_CORE, 0xD001611, "ZDD" };
35 }
36 } // end namespace DistributedData
37
38 namespace DistributedKVStore {
LogLabel()39 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
40 {
41 return { LOG_CORE, 0xD001612, "ZDD" };
42 }
43 } // end namespace DistributedKVStore
44
45 namespace CloudData {
LogLabel()46 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
47 {
48 return { LOG_CORE, 0xD001613, "CLOUD" };
49 }
50 } // end namespace CloudData
51
52 namespace UDMF {
LogLabel()53 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
54 {
55 return { LOG_CORE, 0xD001614, "UDMF" };
56 }
57 } // end namespace UDMF
58
59 namespace AppDistributedKv {
LogLabel()60 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
61 {
62 return { LOG_CORE, 0xD001620, "ZDDC" };
63 }
64 } // namespace AppDistributedKv
65
66 namespace DistributedRdb {
LogLabel()67 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
68 {
69 return { LOG_CORE, 0xD001655, "DRDB" };
70 }
71 } // end namespace DistributedRdb
72
73 namespace DataShare {
LogLabel()74 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
75 {
76 return { LOG_CORE, 0xD001651, "DataShare" };
77 }
78 } // end namespace DataShare
79
80 namespace DistributedObject {
LogLabel()81 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
82 {
83 return { LOG_CORE, 0xD001654, "DOBJECT" };
84 }
85 } // end namespace DistributedObject
86
87 namespace DataSearchable {
LogLabel()88 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
89 {
90 return { LOG_CORE, 0xD001656, "DSRCH" };
91 }
92 } // end namespace DataSearchable
93 } // end namespace OHOS
94
95 #define ZLOGD(fmt, ...) \
96 do { \
97 using HiLog = OHOS::HiviewDFX::HiLog; \
98 auto lable = LogLabel(); \
99 if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_DEBUG)) { \
100 break; \
101 } \
102 HiLog::Debug(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
103 } while (0)
104
105 #define ZLOGI(fmt, ...) \
106 do { \
107 using HiLog = OHOS::HiviewDFX::HiLog; \
108 auto lable = LogLabel(); \
109 if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_INFO)) { \
110 break; \
111 } \
112 HiLog::Info(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
113 } while (0)
114
115 #define ZLOGW(fmt, ...) \
116 do { \
117 using HiLog = OHOS::HiviewDFX::HiLog; \
118 auto lable = LogLabel(); \
119 if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_WARN)) { \
120 break; \
121 } \
122 HiLog::Warn(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
123 } while (0)
124
125 #define ZLOGE(fmt, ...) \
126 do { \
127 using HiLog = OHOS::HiviewDFX::HiLog; \
128 auto lable = LogLabel(); \
129 if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_ERROR)) { \
130 break; \
131 } \
132 HiLog::Error(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
133 } while (0)
134
135 #else
136 #error // unknown system
137 #endif
138
139 #endif // DISTRIBUTEDDATA_LOG_PRINT_H