• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef PRE_LOG_PRINTF_H
16 #define PRE_LOG_PRINTF_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "hilog/log.h"
22 
23 namespace OHOS {
24 namespace PreferencesJsKit {
LogLabel()25 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
26 {
27     return { LOG_CORE, 0xD001653, "PreferencesJsKit" };
28 }
29 }
30 
31 namespace NativePreferences {
LogLabel()32 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
33 {
34     return { LOG_CORE, 0xD001653, "NativePreferences" };
35 }
36 }
37 
38 namespace PreferencesNdk {
LogLabel()39 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
40 {
41     return { LOG_CORE, 0xD001653, "PreferencesNdk" };
42 }
43 }
44 
45 namespace StorageJsKit {
LogLabel()46 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
47 {
48     return { LOG_CORE, 0xD001653, "StorageJsKit" };
49 }
50 }
51 namespace Sendable::JSPreferences {
LogLabel()52 static inline OHOS::HiviewDFX::HiLogLabel LogLabel()
53 {
54     return { LOG_CORE, 0xD001653, "JSPreferences" };
55 }
56 }
57 
58 } // namespace OHOS
59 #define LOG_DEBUG(fmt, ...)                                                             \
60     do {                                                                                \
61         auto lable = LogLabel();                                                        \
62         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) {            \
63             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_DEBUG, lable.domain, lable.tag, \
64                               "%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));        \
65         }                                                                               \
66     } while (0)
67 
68 #define LOG_INFO(fmt, ...)                                                              \
69     do {                                                                                \
70         auto lable = LogLabel();                                                        \
71         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) {             \
72             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_INFO, lable.domain, lable.tag,  \
73                               "%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));        \
74         }                                                                               \
75     } while (0)
76 
77 #define LOG_WARN(fmt, ...)                                                              \
78     do {                                                                                \
79         auto lable = LogLabel();                                                        \
80         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) {             \
81             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_WARN, lable.domain, lable.tag,  \
82                               "%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));        \
83         }                                                                               \
84     } while (0)
85 
86 #define LOG_ERROR(fmt, ...)                                                             \
87     do {                                                                                \
88         auto lable = LogLabel();                                                        \
89         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) {            \
90             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_ERROR, lable.domain, lable.tag, \
91                               "%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));        \
92         }                                                                               \
93     } while (0)
94 
95 #define LOG_FATAL(fmt, ...)                                                             \
96     do {                                                                                \
97         auto lable = LogLabel();                                                        \
98         if (HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) {            \
99             ((void)HILOG_IMPL(lable.type, LogLevel::LOG_FATAL, lable.domain, lable.tag, \
100                               "%{public}s: " fmt, __FUNCTION__, ##__VA_ARGS__));        \
101         }                                                                               \
102     } while (0)
103 
104 #endif
105