1 /* 2 * Copyright (c) 2021-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 OS_ACCOUNT_FRAMEWORKS_COMMON_LOG_INCLUDE_ACCOUNT_LOG_WRAPPER_H 17 #define OS_ACCOUNT_FRAMEWORKS_COMMON_LOG_INCLUDE_ACCOUNT_LOG_WRAPPER_H 18 19 #include <string> 20 #include "hilog/log.h" 21 22 namespace OHOS { 23 namespace AccountSA { 24 #ifdef __FILE_NAME__ 25 #define LOG_FILE_NAME __FILE_NAME__ 26 #else 27 #define LOG_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 28 #endif 29 30 enum class AccountLogLevel { DEBUG = 0, INFO, WARN, ERROR, FATAL }; 31 constexpr OHOS::HiviewDFX::HiLogLabel ACCOUNT_LABEL = {LOG_CORE, LOG_DOMAIN, ACCOUNT_LOG_TAG}; 32 33 class AccountLogWrapper { 34 public: 35 static bool JudgeLevel(const AccountLogLevel &level); 36 SetLogLevel(const AccountLogLevel & level)37 static void SetLogLevel(const AccountLogLevel &level) 38 { 39 level_ = level; 40 } 41 GetLogLevel()42 static const AccountLogLevel &GetLogLevel() 43 { 44 return level_; 45 } 46 47 static std::string GetBriefFileName(const std::string &file); 48 49 private: 50 static AccountLogLevel level_; 51 }; 52 53 #define ARGS(fmt, ...) "[%{public}s@%{public}s:%{public}d] " fmt, __FUNCTION__, LOG_FILE_NAME, __LINE__, ##__VA_ARGS__ 54 #define ACCOUNT_LOGD(...) OHOS::HiviewDFX::HiLog::Debug(ACCOUNT_LABEL, ARGS(__VA_ARGS__)) 55 #define ACCOUNT_LOGI(...) OHOS::HiviewDFX::HiLog::Info(ACCOUNT_LABEL, ARGS(__VA_ARGS__)) 56 #define ACCOUNT_LOGW(...) OHOS::HiviewDFX::HiLog::Warn(ACCOUNT_LABEL, ARGS(__VA_ARGS__)) 57 #define ACCOUNT_LOGE(...) OHOS::HiviewDFX::HiLog::Error(ACCOUNT_LABEL, ARGS(__VA_ARGS__)) 58 #define ACCOUNT_LOGF(...) OHOS::HiviewDFX::HiLog::Fatal(ACCOUNT_LABEL, ARGS(__VA_ARGS__)) 59 } // namespace AccountSA 60 } // namespace OHOS 61 62 #endif // OS_ACCOUNT_FRAMEWORKS_COMMON_LOG_INCLUDE_ACCOUNT_LOG_WRAPPER_H 63