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 
94 namespace ConnectInner {
LogLabel()95     static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
96     {
97         return { LOG_CORE, 0xD001610, "Connect" };
98     }
99 } // end namespace ConnectInner
100 } // end namespace OHOS
101 
102 #define ZLOGD(fmt, ...)                                                   \
103     do {                                                                  \
104         auto lable = LogLabel();                                          \
105         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_DEBUG)) {       \
106             break;                                                        \
107         }                                                                 \
108         ((void)HILOG_IMPL(lable.type, LOG_DEBUG, lable.domain, lable.tag, \
109             LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));  \
110     } while (0)
111 
112 #define ZLOGI(fmt, ...)                                                   \
113     do {                                                                  \
114         auto lable = LogLabel();                                          \
115         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_INFO)) {        \
116             break;                                                        \
117         }                                                                 \
118         ((void)HILOG_IMPL(lable.type, LOG_INFO, lable.domain, lable.tag,  \
119             LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));  \
120     } while (0)
121 
122 #define ZLOGW(fmt, ...)                                                   \
123     do {                                                                  \
124         auto lable = LogLabel();                                          \
125         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_WARN)) {        \
126             break;                                                        \
127         }                                                                 \
128         ((void)HILOG_IMPL(lable.type, LOG_WARN, lable.domain, lable.tag,  \
129             LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));  \
130     } while (0)
131 
132 #define ZLOGE(fmt, ...)                                                   \
133     do {                                                                  \
134         auto lable = LogLabel();                                          \
135         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_ERROR)) {       \
136             break;                                                        \
137         }                                                                 \
138         ((void)HILOG_IMPL(lable.type, LOG_ERROR, lable.domain, lable.tag, \
139             LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));  \
140     } while (0)                                   \
141 
142 #else
143     #error // unknown system
144 #endif
145 
146 #endif // DISTRIBUTEDDATA_LOG_PRINT_H