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