• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 } // end namespace OHOS
87 
88 #define ZLOGD(fmt, ...)                                                                 \
89     do {                                                                                \
90         using HiLog = OHOS::HiviewDFX::HiLog;                                           \
91         auto lable = LogLabel();                                                        \
92         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_DEBUG)) {                     \
93             break;                                                                      \
94         }                                                                               \
95         HiLog::Debug(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
96     } while (0)
97 
98 #define ZLOGI(fmt, ...)                                                                \
99     do {                                                                               \
100         using HiLog = OHOS::HiviewDFX::HiLog;                                          \
101         auto lable = LogLabel();                                                       \
102         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_INFO)) {                     \
103             break;                                                                     \
104         }                                                                              \
105         HiLog::Info(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
106     } while (0)
107 
108 #define ZLOGW(fmt, ...)                                                                \
109     do {                                                                               \
110         using HiLog = OHOS::HiviewDFX::HiLog;                                          \
111         auto lable = LogLabel();                                                       \
112         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_WARN)) {                     \
113             break;                                                                     \
114         }                                                                              \
115         HiLog::Warn(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
116     } while (0)
117 
118 #define ZLOGE(fmt, ...)                                                                 \
119     do {                                                                                \
120         using HiLog = OHOS::HiviewDFX::HiLog;                                           \
121         auto lable = LogLabel();                                                        \
122         if (!HiLogIsLoggable(lable.domain, lable.tag, LOG_ERROR)) {                     \
123             break;                                                                      \
124         }                                                                               \
125         HiLog::Error(lable, LOG_TAG "::%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__); \
126     } while (0)
127 
128 #else
129     #error // unknown system
130 #endif
131 
132 #endif // DISTRIBUTEDDATA_LOG_PRINT_H