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 constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0xD001C30, "SclockKit" };
46 static constexpr uint32_t KG_DOMAIN_ID = 0xD001C30;
47 static const char* KG_TAG = "SclockKit";
48 
49 #define FILENAME_PREFIX (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
50 
51 #define SCLOCK_HILOGF(fmt, ...)          \
52     HILOG_IMPL(LOG_CORE, LOG_FATAL, KG_DOMAIN_ID, \
53         KG_TAG, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME_PREFIX, __FUNCTION__, __LINE__, ##__VA_ARGS__)
54 #define SCLOCK_HILOGE(fmt, ...)          \
55     HILOG_IMPL(LOG_CORE, LOG_ERROR, KG_DOMAIN_ID, \
56         KG_TAG, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME_PREFIX, __FUNCTION__, __LINE__, ##__VA_ARGS__)
57 #define SCLOCK_HILOGW(fmt, ...)         \
58     HILOG_IMPL(LOG_CORE, LOG_WARN, KG_DOMAIN_ID, \
59         KG_TAG, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME_PREFIX, __FUNCTION__, __LINE__, ##__VA_ARGS__)
60 #define SCLOCK_HILOGI(fmt, ...)         \
61     HILOG_IMPL(LOG_CORE, LOG_INFO, KG_DOMAIN_ID, \
62         KG_TAG, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME_PREFIX, __FUNCTION__, __LINE__, ##__VA_ARGS__)
63 #define SCLOCK_HILOGD(fmt, ...)          \
64     HILOG_IMPL(LOG_CORE, LOG_DEBUG, KG_DOMAIN_ID, \
65         KG_TAG, "[%{public}s(%{public}s:%{public}d)]" fmt, FILENAME_PREFIX, __FUNCTION__, __LINE__, ##__VA_ARGS__)
66 #else
67 
68 #define SCLOCK_HILOGF(...)
69 #define SCLOCK_HILOGE(...)
70 #define SCLOCK_HILOGW(...)
71 #define SCLOCK_HILOGI(...)
72 #define SCLOCK_HILOGD(...)
73 #endif // CONFIG_HILOG
74 #endif // BASE_SMALLSERVICE_SCLOCK_LOG_H
75