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