1 /*
2 * Copyright (c) 2023 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 RDB_LOGGER_H
17 #define RDB_LOGGER_H
18
19 #include "hilog/log.h"
20
21 namespace OHOS {
22 namespace Rdb {
LogLabel()23 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
24 {
25 return { LOG_CORE, 0xD001650, "Rdb" };
26 }
27 } // namespace Rdb
28
29 namespace RdbNdk {
LogLabel()30 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
31 {
32 return { LOG_CORE, 0xD001656, "RdbNdk" };
33 }
34 } // namespace RdbNdk
35 } // namespace OHOS
36
37 #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
38
39 #define LOG_DEBUG(fmt, ...) \
40 do { \
41 using HiLog = OHOS::HiviewDFX::HiLog; \
42 auto lable = LogLabel(); \
43 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) { \
44 HiLog::Debug(lable, "::[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
45 ##__VA_ARGS__); \
46 } \
47 } while (0)
48
49 #define LOG_INFO(fmt, ...) \
50 do { \
51 using HiLog = OHOS::HiviewDFX::HiLog; \
52 auto lable = LogLabel(); \
53 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) { \
54 HiLog::Info(lable, "::[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
55 ##__VA_ARGS__); \
56 } \
57 } while (0)
58
59 #define LOG_WARN(fmt, ...) \
60 do { \
61 using HiLog = OHOS::HiviewDFX::HiLog; \
62 auto lable = LogLabel(); \
63 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) { \
64 HiLog::Warn(lable, "::[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
65 ##__VA_ARGS__); \
66 } \
67 } while (0)
68
69 #define LOG_ERROR(fmt, ...) \
70 do { \
71 using HiLog = OHOS::HiviewDFX::HiLog; \
72 auto lable = LogLabel(); \
73 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) { \
74 HiLog::Error(lable, "::[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
75 ##__VA_ARGS__); \
76 } \
77 } while (0)
78
79 #define LOG_FATAL(fmt, ...) \
80 do { \
81 using HiLog = OHOS::HiviewDFX::HiLog; \
82 auto lable = LogLabel(); \
83 if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) { \
84 HiLog::Fatal(lable, "::[%{public}s()-%{public}s:%{public}d]: " fmt, __FUNCTION__, FILENAME, __LINE__, \
85 ##__VA_ARGS__); \
86 } \
87 } while (0)
88
89 #endif // RDB_LOGGER_H
90