• 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 TIME_HILOG_WRAPPER_H
17 #define TIME_HILOG_WRAPPER_H
18 
19 #include "hilog/log.h"
20 
21 namespace OHOS {
22 namespace MiscServices {
23 // param of log interface, such as TIME_HILOGF.
24 enum TimeSubModule {
25     TIME_MODULE_INNERKIT = 0,
26     TIME_MODULE_CLIENT,
27     TIME_MODULE_SERVICE,
28     TIME_MODULE_JAVAKIT, // java kit, defined to avoid repeated use of domain.
29     TIME_MODULE_JNI,
30     TIME_MODULE_COMMON,
31     TIME_MODULE_JS_NAPI,
32     TIME_MODULE_BUTT,
33 };
34 
35 static constexpr unsigned int BASE_TIME_DOMAIN_ID = 0xD001C04;
36 
37 enum TimeDomainId {
38     TIME_INNERKIT_DOMAIN = BASE_TIME_DOMAIN_ID + TIME_MODULE_INNERKIT,
39     TIME_CLIENT_DOMAIN,
40     TIME_SERVICE_DOMAIN,
41     TIME_JAVAKIT_DOMAIN,
42     TIME_JNI_DOMAIN,
43     TIME_COMMON_DOMAIN,
44     TIME_JS_NAPI,
45     TIME_BUTT,
46 };
47 
48 static constexpr OHOS::HiviewDFX::HiLogLabel TIME_MODULE_LABEL[TIME_MODULE_BUTT] = {
49     { LOG_CORE, TIME_INNERKIT_DOMAIN, "TimeInnerKit" },
50     { LOG_CORE, TIME_CLIENT_DOMAIN, "TimeClient" },
51     { LOG_CORE, TIME_SERVICE_DOMAIN, "TimeService" },
52     { LOG_CORE, TIME_JAVAKIT_DOMAIN, "TimeJavaKit" },
53     { LOG_CORE, TIME_JNI_DOMAIN, "TimeJni" },
54     { LOG_CORE, TIME_COMMON_DOMAIN, "TimeCommon" },
55     { LOG_CORE, TIME_JS_NAPI, "TimeJSNAPI" },
56 };
57 
58 #define R_FILENAME_ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
59 #define R_FORMATED(fmt, ...) "[%{public}s] %{public}s# " fmt, R_FILENAME_, __FUNCTION__, ##__VA_ARGS__
60 
61 // In order to improve performance, do not check the module range.
62 // Besides, make sure module is less than TIME_MODULE_BUTT.
63 #define TIME_HILOGF(module, ...) \
64     (void)OHOS::HiviewDFX::HiLog::Fatal(TIME_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
65 #define TIME_HILOGE(module, ...) \
66     (void)OHOS::HiviewDFX::HiLog::Error(TIME_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
67 #define TIME_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(TIME_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
68 #define TIME_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(TIME_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
69 #define TIME_HILOGD(module, ...) \
70     (void)OHOS::HiviewDFX::HiLog::Debug(TIME_MODULE_LABEL[module], R_FORMATED(__VA_ARGS__))
71 
72 #define CHECK_AND_RETURN_RET_LOG(module, cond, ret, ...)  \
73     do {                                                  \
74         if (!(cond)) {                                    \
75             TIME_HILOGE(module, R_FORMATED(__VA_ARGS__)); \
76             return ret;                                   \
77         }                                                 \
78     } while (0)
79 
80 #define CHECK_AND_RETURN_LOG(module, cond, ...)           \
81     do {                                                  \
82         if (!(cond)) {                                    \
83             TIME_HILOGE(module, R_FORMATED(__VA_ARGS__)); \
84             return;                                       \
85         }                                                 \
86     } while (0)
87 
88 } // namespace MiscServices
89 } // namespace OHOS
90 #endif // TIME_HILOG_WRAPPER_H