• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
29 
30 #define LOG_DEBUG(fmt, ...)                                                               \
31     do {                                                                                  \
32         using HiLog = OHOS::HiviewDFX::HiLog;                                             \
33         auto lable = LogLabel();                                                          \
34         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) {              \
35             HiLog::Debug(lable, "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
36                 ##__VA_ARGS__);                                                           \
37         }                                                                                 \
38     } while (0)
39 
40 #define LOG_INFO(fmt, ...)                                                                \
41     do {                                                                                  \
42         using HiLog = OHOS::HiviewDFX::HiLog;                                             \
43         auto lable = LogLabel();                                                          \
44         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) {               \
45             HiLog::Info(lable, "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
46                 ##__VA_ARGS__);                                                           \
47         }                                                                                 \
48     } while (0)
49 
50 #define LOG_WARN(fmt, ...)                                                                \
51     do {                                                                                  \
52         using HiLog = OHOS::HiviewDFX::HiLog;                                             \
53         auto lable = LogLabel();                                                          \
54         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) {               \
55             HiLog::Warn(lable, "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
56                 ##__VA_ARGS__);                                                           \
57         }                                                                                 \
58     } while (0)
59 
60 #define LOG_ERROR(fmt, ...)                                                               \
61     do {                                                                                  \
62         using HiLog = OHOS::HiviewDFX::HiLog;                                             \
63         auto lable = LogLabel();                                                          \
64         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) {              \
65             HiLog::Error(lable, "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
66                 ##__VA_ARGS__);                                                           \
67         }                                                                                 \
68     } while (0)
69 
70 #define LOG_FATAL(fmt, ...)                                                               \
71     do {                                                                                  \
72         using HiLog = OHOS::HiviewDFX::HiLog;                                             \
73         auto lable = LogLabel();                                                          \
74         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) {              \
75             HiLog::Fatal(lable, "[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
76                 ##__VA_ARGS__);                                                           \
77         }                                                                                 \
78     } while (0)
79 
80 #endif // DATASHARE_LOG_PRINT_H
81