• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 
24 #ifdef BATTERY_HILOGF
25 #undef BATTERY_HILOGF
26 #endif
27 
28 #ifdef BATTERY_HILOGE
29 #undef BATTERY_HILOGE
30 #endif
31 
32 #ifdef BATTERY_HILOGW
33 #undef BATTERY_HILOGW
34 #endif
35 
36 #ifdef BATTERY_HILOGI
37 #undef BATTERY_HILOGI
38 #endif
39 
40 #ifdef BATTERY_HILOGD
41 #undef BATTERY_HILOGD
42 #endif
43 
44 namespace {
45 // Battery manager reserved domain id range
46 constexpr unsigned int BATTERY_DOMAIN_ID_START = 0xD002920;
47 constexpr unsigned int BATTERY_DOMAIN_ID_END = BATTERY_DOMAIN_ID_START + 32;
48 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
49 } // namespace
50 
51 enum BatteryManagerLogLabel {
52     // Component labels, you can add if needed
53     COMP_APP = 0,
54     COMP_FWK = 1,
55     COMP_SVC = 2,
56     COMP_HDI = 3,
57     COMP_DRV = 4,
58     // Feature labels, use to mark major features
59     FEATURE_CHARGING,
60     FEATURE_BATT_INFO,
61     FEATURE_BATT_LIGHT,
62     // Test label
63     LABEL_TEST,
64     // The end of labels, max to the domain id range length 32
65     LABEL_END,
66 };
67 
68 enum BatteryManagerLogDomain {
69     DOMAIN_APP = BATTERY_DOMAIN_ID_START + COMP_APP, // 0xD002920
70     DOMAIN_FRAMEWORK,                                // 0xD002921
71     DOMAIN_SERVICE,                                  // 0xD002922
72     DOMAIN_HDI,                                      // 0xD002923
73     DOMAIN_DRIVER,                                   // 0xD002924
74     DOMAIN_FEATURE_CHARGING,
75     DOMAIN_FEATURE_BATT_INFO,
76     DOMAIN_FEATURE_BATT_LIGHT,
77     DOMAIN_TEST = TEST_DOMAIN_ID,       // 0xD000F00
78     DOMAIN_END = BATTERY_DOMAIN_ID_END, // Max to 0xD002940, keep the sequence and length same as BatteryManagerLogLabel
79 };
80 
81 struct BatteryManagerLogLabelDomain {
82     uint32_t domainId;
83     const char* tag;
84 };
85 
86 // Keep the sequence and length same as BatteryManagerLogDomain
87 static const BatteryManagerLogLabelDomain BATTERY_LABEL[LABEL_END] = {
88     {DOMAIN_APP,                "BatteryApp"     },
89     {DOMAIN_FRAMEWORK,          "BatteryFwk"     },
90     {DOMAIN_SERVICE,            "BatterySvc"     },
91     {DOMAIN_HDI,                "BatteryHdi"     },
92     {DOMAIN_DRIVER,             "BatteryDrv"     },
93     {DOMAIN_FEATURE_CHARGING,   "BatteryCharging"},
94     {DOMAIN_FEATURE_BATT_INFO,  "BatteryInfo"    },
95     {DOMAIN_FEATURE_BATT_LIGHT, "BatteryLight"   },
96     {DOMAIN_TEST,               "BatteryTest"    },
97 };
98 
99 #define BATTERY_HILOGF(domain, ...) \
100     ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
101 #define BATTERY_HILOGE(domain, ...) \
102     ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
103 #define BATTERY_HILOGW(domain, ...) \
104     ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
105 #define BATTERY_HILOGI(domain, ...) \
106     ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
107 #define BATTERY_HILOGD(domain, ...) \
108     ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
109 } // namespace PowerMgr
110 } // namespace OHOS
111 
112 #endif // BATTERY_LOG_H
113