• 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 PRINT_LOG
17 #define PRINT_LOG
18 
19 #define CONFIG_PRINT_LOG
20 #ifdef CONFIG_PRINT_LOG
21 #include "hilog/log.h"
22 
23 #ifdef PRINT_HILOGF
24 #undef PRINT_HILOGF
25 #endif
26 
27 #ifdef PRINT_HILOGE
28 #undef PRINT_HILOGE
29 #endif
30 
31 #ifdef PRINT_HILOGW
32 #undef PRINT_HILOGW
33 #endif
34 
35 #ifdef PRINT_HILOGD
36 #undef PRINT_HILOGD
37 #endif
38 
39 #ifdef PRINT_HILOGI
40 #undef PRINT_HILOGI
41 #endif
42 
43 #define PRINT_LOG_TAG "printkit"
44 #define PRINT_LOG_DOMAIN 0xD001C00
45 static constexpr OHOS::HiviewDFX::HiLogLabel PRINT_LOG_LABEL = {LOG_CORE, PRINT_LOG_DOMAIN, PRINT_LOG_TAG};
46 
47 #define MAKE_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
48 
49 #define PRINT_HILOGF(fmt, ...)                                        								\
50     (void)OHOS::HiviewDFX::HiLog::Fatal(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt,	\
51     MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
52 
53 #define PRINT_HILOGE(fmt, ...)                                      									\
54     (void)OHOS::HiviewDFX::HiLog::Error(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt,	\
55     MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
56 
57 #define PRINT_HILOGW(fmt, ...)                                                        				\
58     (void)OHOS::HiviewDFX::HiLog::Warn(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt,	\
59     MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
60 
61 #define PRINT_HILOGD(fmt, ...)                                                            			\
62     (void)OHOS::HiviewDFX::HiLog::Debug(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt,	\
63     MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
64 
65 #define PRINT_HILOGI(fmt, ...)                                                     					\
66     (void)OHOS::HiviewDFX::HiLog::Info(PRINT_LOG_LABEL, "[%{public}s %{public}s %{public}d] " fmt,	\
67     MAKE_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__)
68 
69 #else
70 
71 #define PRINT_HILOGF(fmt, ...)
72 #define PRINT_HILOGE(fmt, ...)
73 #define PRINT_HILOGW(fmt, ...)
74 #define PRINT_HILOGD(fmt, ...)
75 #define PRINT_HILOGI(fmt, ...)
76 #endif // CONFIG_PRINT_LOG
77 
78 #endif /* PRINT_LOG */