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 FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_COMMON_INCLUDE_BGTASKMGR_LOG_WRAPPER_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_COMMON_INCLUDE_BGTASKMGR_LOG_WRAPPER_H 18 19 #include <string> 20 21 #include "hilog/log.h" 22 23 namespace OHOS { 24 namespace BackgroundTaskMgr { 25 #ifndef BGTASK_MGR_LOG_DOMAIN 26 #define BGTASK_MGR_LOG_DOMAIN 0xD001711 27 #endif 28 29 #ifndef BGTASK_MGR_LOG_TAG 30 #define BGTASK_MGR_LOG_TAG "BACKGROUND_TASK" 31 #endif 32 33 enum class BgTaskMgrLogLevel : uint8_t { DEBUG = 0, INFO, WARN, ERROR, FATAL }; 34 35 static constexpr OHOS::HiviewDFX::HiLogLabel BGTASK_MGR_LABEL = {LOG_CORE, BGTASK_MGR_LOG_DOMAIN, 36 BGTASK_MGR_LOG_TAG}; 37 38 class BgTaskMgrLogWrapper { 39 public: 40 BgTaskMgrLogWrapper() = delete; 41 ~BgTaskMgrLogWrapper() = delete; 42 43 static bool JudgeLevel(const BgTaskMgrLogLevel &level); 44 SetLogLevel(const BgTaskMgrLogLevel & level)45 static void SetLogLevel(const BgTaskMgrLogLevel &level) 46 { 47 level_ = level; 48 } 49 GetLogLevel()50 static const BgTaskMgrLogLevel &GetLogLevel() 51 { 52 return level_; 53 } 54 55 static std::string GetBriefFileName(const char *str); 56 57 private: 58 static BgTaskMgrLogLevel level_; 59 }; 60 61 #define BGTASK_PRINT_LOG(LEVEL, Level, fmt, ...) \ 62 if (BackgroundTaskMgr::BgTaskMgrLogWrapper::JudgeLevel(BackgroundTaskMgr::BgTaskMgrLogLevel::LEVEL)) \ 63 OHOS::HiviewDFX::HiLog::Level(BackgroundTaskMgr::BGTASK_MGR_LABEL, \ 64 fmt, \ 65 ##__VA_ARGS__) 66 67 #define BGTASK_LOGD(fmt, ...) BGTASK_PRINT_LOG(DEBUG, Debug, fmt, ##__VA_ARGS__) 68 #define BGTASK_LOGI(fmt, ...) BGTASK_PRINT_LOG(INFO, Info, fmt, ##__VA_ARGS__) 69 #define BGTASK_LOGW(fmt, ...) BGTASK_PRINT_LOG(WARN, Warn, fmt, ##__VA_ARGS__) 70 #define BGTASK_LOGE(fmt, ...) BGTASK_PRINT_LOG(ERROR, Error, fmt, ##__VA_ARGS__) 71 #define BGTASK_LOGF(fmt, ...) BGTASK_PRINT_LOG(FATAL, Fatal, fmt, ##__VA_ARGS__) 72 } // namespace BackgroundTaskMgr 73 } // namespace OHOS 74 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_COMMON_INCLUDE_BGTASKMGR_LOG_WRAPPER_H