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