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 enum class AccountLogLevel { DEBUG = 0, INFO, WARN, ERROR, FATAL }; 25 constexpr OHOS::HiviewDFX::HiLogLabel ACCOUNT_LABEL = {LOG_CORE, LOG_DOMAIN, ACCOUNT_LOG_TAG}; 26 27 class AccountLogWrapper { 28 public: 29 static bool JudgeLevel(const AccountLogLevel &level); 30 SetLogLevel(const AccountLogLevel & level)31 static void SetLogLevel(const AccountLogLevel &level) 32 { 33 level_ = level; 34 } 35 GetLogLevel()36 static const AccountLogLevel &GetLogLevel() 37 { 38 return level_; 39 } 40 41 static std::string GetBriefFileName(const std::string &file); 42 43 private: 44 static AccountLogLevel level_; 45 }; 46 47 #define ACCOUNT_LOGD(fmt, ...) \ 48 OHOS::HiviewDFX::HiLog::Debug(ACCOUNT_LABEL, "[%{public}s:%{public}d]:" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__) 49 #define ACCOUNT_LOGI(fmt, ...) \ 50 OHOS::HiviewDFX::HiLog::Info(ACCOUNT_LABEL, "[%{public}s:%{public}d]:" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__) 51 #define ACCOUNT_LOGW(fmt, ...) \ 52 OHOS::HiviewDFX::HiLog::Warn(ACCOUNT_LABEL, "[%{public}s:%{public}d]:" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__) 53 #define ACCOUNT_LOGE(fmt, ...) \ 54 OHOS::HiviewDFX::HiLog::Error(ACCOUNT_LABEL, "[%{public}s:%{public}d]:" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__) 55 #define ACCOUNT_LOGF(fmt, ...) \ 56 OHOS::HiviewDFX::HiLog::Fatal(ACCOUNT_LABEL, "[%{public}s:%{public}d]:" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__) 57 } // namespace AccountSA 58 } // namespace OHOS 59 60 #endif // OS_ACCOUNT_FRAMEWORKS_COMMON_LOG_INCLUDE_ACCOUNT_LOG_WRAPPER_H 61