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 COAUTH_HILOG_WRAPPER_H 17 #define COAUTH_HILOG_WRAPPER_H 18 19 #define CONFIG_HILOG 20 #ifdef CONFIG_HILOG 21 #include "hilog/log.h" 22 namespace OHOS { 23 namespace UserIAM { 24 #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 25 #define FORMATTED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__ 26 27 #ifdef COAUTH_HILOGF 28 #undef COAUTH_HILOGF 29 #endif 30 31 #ifdef COAUTH_HILOGE 32 #undef COAUTH_HILOGE 33 #endif 34 35 #ifdef COAUTH_HILOGW 36 #undef COAUTH_HILOGW 37 #endif 38 39 #ifdef COAUTH_HILOGI 40 #undef COAUTH_HILOGI 41 #endif 42 43 #ifdef COAUTH_HILOGD 44 #undef COAUTH_HILOGD 45 #endif 46 47 // param of log interface, such as COAUTH_HILOGF. 48 enum CoauthSubModule { 49 MODULE_INNERKIT = 0, 50 MODULE_SERVICE, 51 MODULE_COMMON, 52 MODULE_JS_NAPI, 53 COAUTH_MODULE_BUTT, 54 }; 55 56 // 0xD002900: subsystem:distributeddatamgr module:distributedgallery, 8 bits reserved. 57 static constexpr unsigned int BASE_COAUTH_DOMAIN_ID = 0xD002910; 58 59 enum CoauthDomainId { 60 COAUTH_INNERKIT_DOMAIN = BASE_COAUTH_DOMAIN_ID + MODULE_INNERKIT, 61 COAUTH_SERVICE_DOMAIN, 62 COMMON_DOMAIN, 63 COAUTH_JS_NAPI, 64 COAUTH_BUTT, 65 }; 66 67 static constexpr OHOS::HiviewDFX::HiLogLabel COAUTH_LABEL[COAUTH_MODULE_BUTT] = { 68 {LOG_CORE, COAUTH_INNERKIT_DOMAIN, "CoAuth"}, 69 {LOG_CORE, COAUTH_SERVICE_DOMAIN, "CoAuthService"}, 70 {LOG_CORE, COMMON_DOMAIN, "CoAuthCommon"}, 71 {LOG_CORE, COAUTH_JS_NAPI, "CoAuthJSNAPI"}, 72 }; 73 74 // In order to improve performance, do not check the module range. 75 // Besides, make sure module is less than COAUTH_MODULE_BUTT. 76 #define COAUTH_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 77 #define COAUTH_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 78 #define COAUTH_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 79 #define COAUTH_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 80 #define COAUTH_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(COAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 81 } // namespace UserIAM 82 } // namespace OHOS 83 84 #else 85 86 #define COAUTH_HILOGF(...) 87 #define COAUTH_HILOGE(...) 88 #define COAUTH_HILOGW(...) 89 #define COAUTH_HILOGI(...) 90 #define COAUTH_HILOGD(...) 91 92 #endif // CONFIG_HILOG 93 94 #endif // COAUTH_HILOG_WRAPPER_H 95