1 /* 2 * Copyright (c) 2021 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 #ifndef HIDUMPER_UTILS_HILOG_WRAPPER_H 16 #define HIDUMPER_UTILS_HILOG_WRAPPER_H 17 #define CONFIG_HILOG 18 #ifdef CONFIG_HILOG 19 #include "hilog/log.h" 20 namespace OHOS { 21 namespace HiviewDFX { 22 #ifdef DUMPER_HILOGF 23 #undef DUMPER_HILOGF 24 #endif 25 #ifdef DUMPER_HILOGE 26 #undef DUMPER_HILOGE 27 #endif 28 #ifdef DUMPER_HILOGW 29 #undef DUMPER_HILOGW 30 #endif 31 #ifdef DUMPER_HILOGI 32 #undef DUMPER_HILOGI 33 #endif 34 #ifdef DUMPER_HILOGD 35 #undef DUMPER_HILOGD 36 #endif 37 // param of log interface, such as DUMPER_HILOGF. 38 enum DumperSubModule { 39 MODULE_COMMON = 0, 40 MODULE_ZIDL, 41 MODULE_CLIENT, 42 MODULE_SERVICE, 43 MODULE_CPU_SERVICE, 44 MODULE_CPU_ZIDL, 45 MODULE_CPU_CLIENT, 46 MODULE_CPU_DATA, 47 MODULE_MAX, 48 }; 49 // 0xD002900: subsystem:DumperMgr module:DumperManager, 8 bits reserved. 50 static constexpr unsigned int BASE_DUMPER_DOMAIN_ID = 0xD002900; 51 enum DumperMgrDomainId { 52 DUMPER_COMMON_DOMAIN = BASE_DUMPER_DOMAIN_ID + MODULE_COMMON, 53 DUMPER_ZIDL_DOMAIN, 54 DUMPER_CLIENT_DOMAIN, 55 DUMPER_SERVICE_DOMAIN, 56 DUMPER_CPU_SERVICE_DOMAIN, 57 DUMPER_CPU_ZIDL_DOMAIN, 58 DUMPER_CPU_CLIENT_DOMAIN, 59 DUMPER_CPU_DATA 60 }; 61 static constexpr OHOS::HiviewDFX::HiLogLabel DUMPER_LABEL[MODULE_MAX] = { 62 {LOG_CORE, DUMPER_COMMON_DOMAIN, "DumperCommon"}, 63 {LOG_CORE, DUMPER_ZIDL_DOMAIN, "DumperZIDL"}, 64 {LOG_CORE, DUMPER_CLIENT_DOMAIN, "DumperClient"}, 65 {LOG_CORE, DUMPER_SERVICE_DOMAIN, "DumperService"}, 66 {LOG_CORE, DUMPER_CPU_SERVICE_DOMAIN, "DumperCpuService"}, 67 {LOG_CORE, DUMPER_CPU_ZIDL_DOMAIN, "DumperCpuZIDL"}, 68 {LOG_CORE, DUMPER_CPU_CLIENT_DOMAIN, "DumperCpuClient"}, 69 {LOG_CORE, DUMPER_CPU_DATA, "DumperCpuData"}, 70 }; 71 // In order to improve performance, do not check the module range. 72 // Besides, make sure module is less than DUMPER_MAX_DOMAIN. 73 #define DUMPER_HILOGF(module, fmt, ...) \ 74 (void)OHOS::HiviewDFX::HiLog::Fatal(DUMPER_LABEL[module], "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__) 75 #define DUMPER_HILOGE(module, fmt, ...) \ 76 (void)OHOS::HiviewDFX::HiLog::Error(DUMPER_LABEL[module], "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__) 77 #define DUMPER_HILOGW(module, fmt, ...) \ 78 (void)OHOS::HiviewDFX::HiLog::Warn(DUMPER_LABEL[module], "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__) 79 #define DUMPER_HILOGI(module, fmt, ...) \ 80 (void)OHOS::HiviewDFX::HiLog::Info(DUMPER_LABEL[module], "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__) 81 #define DUMPER_HILOGD(module, fmt, ...) \ 82 (void)OHOS::HiviewDFX::HiLog::Debug(DUMPER_LABEL[module], "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__) 83 } // namespace HiviewDFX 84 } // namespace OHOS 85 #else 86 #define DUMPER_HILOGF(...) 87 #define DUMPER_HILOGE(...) 88 #define DUMPER_HILOGW(...) 89 #define DUMPER_HILOGI(...) 90 #define DUMPER_HILOGD(...) 91 #endif // CONFIG_HILOG 92 #endif // HIDUMPER_UTILS_HILOG_WRAPPER_H 93