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 PINAUTH_LOG_WRAPPER_H 17 #define PINAUTH_LOG_WRAPPER_H 18 19 #define CONFIG_HILOG 20 #ifdef CONFIG_HILOG 21 22 #include <string> 23 #include "hilog/log.h" 24 25 namespace OHOS { 26 namespace UserIAM { 27 namespace PinAuth { 28 #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 29 #define FORMATTED(fmt, ...) "[%{public}s] %{public}s# " fmt, FILENAME, __FUNCTION__, ##__VA_ARGS__ 30 31 #ifdef PINAUTH_HILOGF 32 #undef PINAUTH_HILOGF 33 #endif 34 35 #ifdef PINAUTH_HILOGE 36 #undef PINAUTH_HILOGE 37 #endif 38 39 #ifdef PINAUTH_HILOGW 40 #undef PINAUTH_HILOGW 41 #endif 42 43 #ifdef PINAUTH_HILOGI 44 #undef PINAUTH_HILOGI 45 #endif 46 47 #ifdef PINAUTH_HILOGD 48 #undef PINAUTH_HILOGD 49 #endif 50 51 enum PinAuthModule { 52 MODULE_INNERKIT = 0, 53 MODULE_SERVICE, 54 MODULE_COMMON, 55 MODULE_FRAMEWORKS, 56 MODULE_JS_NAPI, 57 PINAUTH_MODULE_BUTT, 58 }; 59 60 static constexpr unsigned int BASE_PINAUTH_DOMAIN_ID = 0xD002910; 61 62 enum PinAuthDomainId { 63 PINAUTH_INNERKIT_DOMAIN = BASE_PINAUTH_DOMAIN_ID + MODULE_INNERKIT, 64 PINAUTH_SERVICE_DOMAIN, 65 COMMON_DOMAIN, 66 PINAUTH_JS_NAPI, 67 PINAUTH_BUTT, 68 }; 69 70 static constexpr OHOS::HiviewDFX::HiLogLabel PINAUTH_LABEL[PINAUTH_MODULE_BUTT] = { 71 {LOG_CORE, PINAUTH_INNERKIT_DOMAIN, "PinAuth"}, 72 {LOG_CORE, PINAUTH_SERVICE_DOMAIN, "PinAuthService"}, 73 {LOG_CORE, COMMON_DOMAIN, "PinAuthCommon"}, 74 {LOG_CORE, PINAUTH_JS_NAPI, "PinAuthJSNAPI"}, 75 }; 76 77 #define PINAUTH_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(PINAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 78 #define PINAUTH_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(PINAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 79 #define PINAUTH_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(PINAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 80 #define PINAUTH_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(PINAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 81 #define PINAUTH_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(PINAUTH_LABEL[module], FORMATTED(__VA_ARGS__)) 82 } // namespace PinAuth 83 } // namespace UserIAM 84 } // namespace OHOS 85 86 #else 87 88 #define PINAUTH_HILOGF(...) 89 #define PINAUTH_HILOGE(...) 90 #define PINAUTH_HILOGW(...) 91 #define PINAUTH_HILOGI(...) 92 #define PINAUTH_HILOGD(...) 93 94 #endif // CONFIG_HILOG 95 96 #endif // PINAUTH_LOG_WRAPPER_H