1 /*
2  * Copyright (c) 2022 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 DATASHARE_LOG_PRINT_H
17 #define DATASHARE_LOG_PRINT_H
18 
19 #include "hilog/log.h"
20 
21 namespace OHOS::DataShare {
LogLabel()22 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
23 {
24     return { LOG_CORE, 0xD001651, "DataShare" };
25 }
26 } // namespace OHOS::DataShare
27 
28 #define LOG_DEBUG(fmt, ...)                                                               \
29     do {                                                                                  \
30         auto lable = LogLabel();                                                          \
31         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) {              \
32             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_DEBUG, lable.domain, lable.tag,   \
33                               "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, \
34                               __FILE_NAME__, __LINE__, ##__VA_ARGS__));                   \
35         }                                                                                 \
36     } while (0)
37 
38 #define LOG_INFO(fmt, ...)                                                                \
39     do {                                                                                  \
40         auto lable = LogLabel();                                                          \
41         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) {               \
42             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_INFO, lable.domain, lable.tag,    \
43                               "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, \
44                               __FILE_NAME__, __LINE__, ##__VA_ARGS__));                   \
45         }                                                                                 \
46     } while (0)
47 
48 #define LOG_WARN(fmt, ...)                                                                \
49     do {                                                                                  \
50         auto lable = LogLabel();                                                          \
51         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) {               \
52             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_WARN, lable.domain, lable.tag,    \
53                               "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, \
54                               __FILE_NAME__, __LINE__, ##__VA_ARGS__));                   \
55         }                                                                                 \
56     } while (0)
57 
58 #define LOG_ERROR(fmt, ...)                                                               \
59     do {                                                                                  \
60         auto lable = LogLabel();                                                          \
61         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) {              \
62             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_ERROR, lable.domain, lable.tag,   \
63                               "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, \
64                               __FILE_NAME__, __LINE__, ##__VA_ARGS__));                   \
65         }                                                                                 \
66     } while (0)
67 
68 #define LOG_FATAL(fmt, ...)                                                               \
69     do {                                                                                  \
70         auto lable = LogLabel();                                                          \
71         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) {              \
72             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_FATAL, lable.domain, lable.tag,   \
73                               "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, \
74                               __FILE_NAME__, __LINE__, ##__VA_ARGS__));                   \
75         }                                                                                 \
76     } while (0)
77 
78 #endif // DATASHARE_LOG_PRINT_H
79