• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 ABILITYBASE_HILOG_WRAPPER_H
17 #define ABILITYBASE_HILOG_WRAPPER_H
18 
19 #define ABILITYBASE_CONFIG_HILOG
20 #ifdef ABILITYBASE_CONFIG_HILOG
21 #include "hilog/log.h"
22 
23 #ifdef ABILITYBASE_LOGF
24 #undef ABILITYBASE_LOGF
25 #endif
26 
27 #ifdef ABILITYBASE_LOGE
28 #undef ABILITYBASE_LOGE
29 #endif
30 
31 #ifdef ABILITYBASE_LOGW
32 #undef ABILITYBASE_LOGW
33 #endif
34 
35 #ifdef ABILITYBASE_LOGI
36 #undef ABILITYBASE_LOGI
37 #endif
38 
39 #ifdef ABILITYBASE_LOGD
40 #undef ABILITYBASE_LOGD
41 #endif
42 
43 #ifndef ABILITYBASE_LOG_DOMAIN
44 #define ABILITYBASE_LOG_DOMAIN 0xD002200
45 #endif
46 
47 #ifndef ABILITYBASE_LOG_TAG
48 #define ABILITYBASE_LOG_TAG "AbilityBase"
49 #endif
50 
51 #ifdef ABILITYBASE_LOG_LABEL
52 #undef ABILITYBASE_LOG_LABEL
53 #endif
54 
55 static constexpr OHOS::HiviewDFX::HiLogLabel ABILITYBASE_LOG_LABEL = {
56     LOG_CORE, ABILITYBASE_LOG_DOMAIN, ABILITYBASE_LOG_TAG};
57 
58 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
59 
60 #define ABILITYBASE_LOGF(fmt, ...)                             \
61     (void)OHOS::HiviewDFX::HiLog::Fatal(ABILITYBASE_LOG_LABEL, \
62         "[%{public}s(%{public}s:%{public}d)]" fmt,             \
63         __FILENAME__,                                          \
64         __FUNCTION__,                                          \
65         __LINE__,                                              \
66         ##__VA_ARGS__)
67 #define ABILITYBASE_LOGE(fmt, ...)                             \
68     (void)OHOS::HiviewDFX::HiLog::Error(ABILITYBASE_LOG_LABEL, \
69         "[%{public}s(%{public}s:%{public}d)]" fmt,             \
70         __FILENAME__,                                          \
71         __FUNCTION__,                                          \
72         __LINE__,                                              \
73         ##__VA_ARGS__)
74 #define ABILITYBASE_LOGW(fmt, ...)                            \
75     (void)OHOS::HiviewDFX::HiLog::Warn(ABILITYBASE_LOG_LABEL, \
76         "[%{public}s(%{public}s:%{public}d)]" fmt,            \
77         __FILENAME__,                                         \
78         __FUNCTION__,                                         \
79         __LINE__,                                             \
80         ##__VA_ARGS__)
81 #define ABILITYBASE_LOGI(fmt, ...)                            \
82     (void)OHOS::HiviewDFX::HiLog::Info(ABILITYBASE_LOG_LABEL, \
83         "[%{public}s(%{public}s:%{public}d)]" fmt,            \
84         __FILENAME__,                                         \
85         __FUNCTION__,                                         \
86         __LINE__,                                             \
87         ##__VA_ARGS__)
88 #define ABILITYBASE_LOGD(fmt, ...)                             \
89     (void)OHOS::HiviewDFX::HiLog::Debug(ABILITYBASE_LOG_LABEL, \
90         "[%{public}s(%{public}s:%{public}d)]" fmt,             \
91         __FILENAME__,                                          \
92         __FUNCTION__,                                          \
93         __LINE__,                                              \
94         ##__VA_ARGS__)
95 #else
96 
97 #define ABILITYBASE_LOGF(...)
98 #define ABILITYBASE_LOGE(...)
99 #define ABILITYBASE_LOGW(...)
100 #define ABILITYBASE_LOGI(...)
101 #define ABILITYBASE_LOGD(...)
102 #endif  // ABILITYBASE_CONFIG_HILOG
103 
104 #endif  // ABILITYBASE_HILOG_WRAPPER_H