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