• 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 BATTERY_LOG_H
17 #define BATTERY_LOG_H
18 
19 #include "hilog/log.h"
20 
21 namespace OHOS {
22 namespace PowerMgr {
23 #define FILENAME         (__builtin_strrchr("/" __FILE__, '/') + 1)
24 #define FORMAT(fmt, ...) "[%{public}s:%{public}d] %{public}s# " fmt, FILENAME, __LINE__, __FUNCTION__, ##__VA_ARGS__
25 
26 #ifdef BATTERY_HILOGF
27 #undef BATTERY_HILOGF
28 #endif
29 
30 #ifdef BATTERY_HILOGE
31 #undef BATTERY_HILOGE
32 #endif
33 
34 #ifdef BATTERY_HILOGW
35 #undef BATTERY_HILOGW
36 #endif
37 
38 #ifdef BATTERY_HILOGI
39 #undef BATTERY_HILOGI
40 #endif
41 
42 #ifdef BATTERY_HILOGD
43 #undef BATTERY_HILOGD
44 #endif
45 
46 namespace {
47 // Battery manager reserved domain id range
48 constexpr unsigned int BATTERY_DOMAIN_ID_START = 0xD002920;
49 constexpr unsigned int BATTERY_DOMAIN_ID_END = BATTERY_DOMAIN_ID_START + 32;
50 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
51 }
52 
53 enum BatteryManagerLogLabel {
54     // Component labels, you can add if needed
55     COMP_APP = 0,
56     COMP_FWK = 1,
57     COMP_SVC = 2,
58     COMP_HDI = 3,
59     COMP_DRV = 4,
60     // Feature labels, use to mark major features
61     FEATURE_CHARGING,
62     FEATURE_BATT_INFO,
63     FEATURE_BATT_LIGHT,
64     // Test label
65     LABEL_TEST,
66     // The end of labels, max to the domain id range length 32
67     LABEL_END,
68 };
69 
70 enum BatteryManagerLogDomain {
71     DOMAIN_APP = BATTERY_DOMAIN_ID_START + COMP_APP, // 0xD002920
72     DOMAIN_FRAMEWORK, // 0xD002921
73     DOMAIN_SERVICE, // 0xD002922
74     DOMAIN_HDI, // 0xD002923
75     DOMAIN_DRIVER, // 0xD002924
76     DOMAIN_FEATURE_CHARGING,
77     DOMAIN_FEATURE_BATT_INFO,
78     DOMAIN_FEATURE_BATT_LIGHT,
79     DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00
80     DOMAIN_END = BATTERY_DOMAIN_ID_END, // Max to 0xD002940, keep the sequence and length same as BatteryManagerLogLabel
81 };
82 
83 // Keep the sequence and length same as BatteryManagerLogDomain
84 static constexpr OHOS::HiviewDFX::HiLogLabel BATTERY_LABEL[LABEL_END] = {
85     {LOG_CORE, DOMAIN_APP,               "BatteryApp"},
86     {LOG_CORE, DOMAIN_FRAMEWORK,         "BatteryFwk"},
87     {LOG_CORE, DOMAIN_SERVICE,           "BatterySvc"},
88     {LOG_CORE, DOMAIN_HDI,               "BatteryHdi"},
89     {LOG_CORE, DOMAIN_DRIVER,            "BatteryDrv"},
90     {LOG_CORE, DOMAIN_FEATURE_CHARGING,  "BatteryCharging"},
91     {LOG_CORE, DOMAIN_FEATURE_BATT_INFO, "BatteryInfo"},
92     {LOG_CORE, DOMAIN_FEATURE_BATT_LIGHT, "BatteryLight"},
93     {LOG_CORE, DOMAIN_TEST,              "BatteryTest"},
94 };
95 
96 #define BATTERY_HILOGF(domain, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(BATTERY_LABEL[domain], FORMAT(__VA_ARGS__))
97 #define BATTERY_HILOGE(domain, ...) (void)OHOS::HiviewDFX::HiLog::Error(BATTERY_LABEL[domain], FORMAT(__VA_ARGS__))
98 #define BATTERY_HILOGW(domain, ...) (void)OHOS::HiviewDFX::HiLog::Warn(BATTERY_LABEL[domain], FORMAT(__VA_ARGS__))
99 #define BATTERY_HILOGI(domain, ...) (void)OHOS::HiviewDFX::HiLog::Info(BATTERY_LABEL[domain], FORMAT(__VA_ARGS__))
100 #define BATTERY_HILOGD(domain, ...) (void)OHOS::HiviewDFX::HiLog::Debug(BATTERY_LABEL[domain], FORMAT(__VA_ARGS__))
101 } // namespace PowerMgr
102 } // namespace OHOS
103 
104 #endif // BATTERY_LOG_H
105