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 DISPLAY_LOG_H 17 #define DISPLAY_LOG_H 18 19 #define CONFIG_HILOG 20 #ifdef CONFIG_HILOG 21 22 #include "hilog/log.h" 23 24 namespace OHOS { 25 namespace DisplayPowerMgr { 26 #define FILE_NAME (__builtin_strrchr("/" __FILE__, '/') + 1) 27 #define FORMAT(fmt, ...) "[%{public}s:%{public}d] %{public}s# " fmt, FILE_NAME, __LINE__, __FUNCTION__, ##__VA_ARGS__ 28 29 #ifdef DISPLAY_HILOGF 30 #undef DISPLAY_HILOGF 31 #endif 32 33 #ifdef DISPLAY_HILOGE 34 #undef DISPLAY_HILOGE 35 #endif 36 37 #ifdef DISPLAY_HILOGW 38 #undef DISPLAY_HILOGW 39 #endif 40 41 #ifdef DISPLAY_HILOGI 42 #undef DISPLAY_HILOGI 43 #endif 44 45 #ifdef DISPLAY_HILOGD 46 #undef DISPLAY_HILOGD 47 #endif 48 49 namespace { 50 // Display manager reserved domain id range 51 constexpr unsigned int DISPLAY_DOMAIN_ID_START = 0xD002980; 52 constexpr unsigned int DISPLAY_DOMAIN_ID_END = DISPLAY_DOMAIN_ID_START + 32; 53 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00; 54 } 55 56 enum DisplayManagerLogLabel { 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 COMP_UTS = 5, 64 FEAT_BRIGHTNESS, 65 FEAT_STATE, 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 DisplayManagerLogDomain { 73 DOMAIN_APP = DISPLAY_DOMAIN_ID_START + COMP_APP, // 0xD002980 74 DOMAIN_FRAMEWORK, // 0xD002981 75 DOMAIN_SERVICE, // 0xD002982 76 DOMAIN_HDI, // 0xD002983 77 DOMAIN_DRIVER, // 0xD002984 78 DOMAIN_UTILS, // 0xD002985 79 DOMAIN_FEAT_BRIGHTNESS, 80 DOMAIN_FEAT_STATE, 81 DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00 82 DOMAIN_END = DISPLAY_DOMAIN_ID_END, // Max to 0xD00299F, keep the sequence and length same as DisplayManagerLogLabel 83 }; 84 85 // Keep the sequence and length same as DisplayManagerLogDomain 86 static constexpr OHOS::HiviewDFX::HiLogLabel DISPLAY_LABEL[LABEL_END] = { 87 {LOG_CORE, DOMAIN_APP, "DisplayPowerApp"}, 88 {LOG_CORE, DOMAIN_FRAMEWORK, "DisplayPowerFwk"}, 89 {LOG_CORE, DOMAIN_SERVICE, "DisplayPowerSvc"}, 90 {LOG_CORE, DOMAIN_HDI, "DisplayPowerHdi"}, 91 {LOG_CORE, DOMAIN_DRIVER, "DisplayPowerDrv"}, 92 {LOG_CORE, DOMAIN_UTILS, "DisplayPowerUts"}, 93 {LOG_CORE, DOMAIN_FEAT_BRIGHTNESS, "DisplayPowerBrightness"}, 94 {LOG_CORE, DOMAIN_FEAT_STATE, "DisplayPowerState"}, 95 {LOG_CORE, DOMAIN_TEST, "DisplayPowerTest"}, 96 }; 97 98 // In order to improve performance, do not check the module range. 99 // Besides, make sure module is less than LABEL_END. 100 #define DISPLAY_HILOGF(domain, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(DISPLAY_LABEL[domain], FORMAT(__VA_ARGS__)) 101 #define DISPLAY_HILOGE(domain, ...) (void)OHOS::HiviewDFX::HiLog::Error(DISPLAY_LABEL[domain], FORMAT(__VA_ARGS__)) 102 #define DISPLAY_HILOGW(domain, ...) (void)OHOS::HiviewDFX::HiLog::Warn(DISPLAY_LABEL[domain], FORMAT(__VA_ARGS__)) 103 #define DISPLAY_HILOGI(domain, ...) (void)OHOS::HiviewDFX::HiLog::Info(DISPLAY_LABEL[domain], FORMAT(__VA_ARGS__)) 104 #define DISPLAY_HILOGD(domain, ...) (void)OHOS::HiviewDFX::HiLog::Debug(DISPLAY_LABEL[domain], FORMAT(__VA_ARGS__)) 105 } // namespace DisplayPowerMgr 106 } // namespace OHOS 107 108 #else 109 110 #define DISPLAY_HILOGF(...) 111 #define DISPLAY_HILOGE(...) 112 #define DISPLAY_HILOGW(...) 113 #define DISPLAY_HILOGI(...) 114 #define DISPLAY_HILOGD(...) 115 116 #endif // CONFIG_HILOG 117 118 #endif // DISPLAY_LOG_H 119