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 RESSCHED_COMMON_INCLUDE_RES_SCHED_LOG_H 17 #define RESSCHED_COMMON_INCLUDE_RES_SCHED_LOG_H 18 19 #include "hilog/log.h" 20 21 namespace OHOS { 22 namespace ResourceSchedule { 23 #define LOG_RESSCHED "RSS" 24 #define LOG_DOMAIN_ID_RESSCHED 0xD001700 25 enum class ResschedLogLevel : uint8_t { DEBUG = 0, INFO, WARN, ERROR, FATAL}; 26 static constexpr OHOS::HiviewDFX::HiLogLabel RES_SCHED_LABEL = { 27 LOG_CORE, 28 LOG_DOMAIN_ID_RESSCHED, 29 LOG_RESSCHED 30 }; 31 class ResschedLog { 32 public: GetInstance()33 static ResschedLog& GetInstance() 34 { 35 static auto instance = new ResschedLog(); 36 return *instance; 37 } getLogEnableByLevel(const ResschedLogLevel & level)38 bool& getLogEnableByLevel(const ResschedLogLevel &level) 39 { 40 if (level == ResschedLogLevel::DEBUG) { 41 return debugLogEnabled_; 42 } else { 43 return otherLogEnable_; 44 } 45 } 46 bool debugLogEnabled_ = false; 47 bool otherLogEnable_ = true; 48 private: ResschedLog()49 ResschedLog() 50 { 51 debugLogEnabled_ = HiLogIsLoggable(LOG_DOMAIN_ID_RESSCHED, LOG_RESSCHED, LOG_DEBUG); 52 } 53 }; 54 #ifdef RESSCHED_LOGF 55 #undef RESSCHED_LOGF 56 #endif 57 58 #ifdef RESSCHED_LOGE 59 #undef RESSCHED_LOGE 60 #endif 61 62 #ifdef RESSCHED_LOGW 63 #undef RESSCHED_LOGW 64 #endif 65 66 #ifdef RESSCHED_LOGI 67 #undef RESSCHED_LOGI 68 #endif 69 70 #ifdef RESSCHED_LOGD 71 #undef RESSCHED_LOGD 72 #endif 73 74 #ifdef RESSCHED_LOG 75 #undef RESSCHED_LOG 76 #endif 77 78 #define RESSCHED_LOG(RESSCHEDLOGLEVEL, level, ...) \ 79 if (ResschedLog::GetInstance().getLogEnableByLevel(RESSCHEDLOGLEVEL)) \ 80 OHOS::HiviewDFX::HiLog::level(RES_SCHED_LABEL, ##__VA_ARGS__) \ 81 82 #define RESSCHED_LOGF(...) RESSCHED_LOG(ResschedLogLevel::FATAL, Fatal, ##__VA_ARGS__) 83 #define RESSCHED_LOGE(...) RESSCHED_LOG(ResschedLogLevel::ERROR, Error, ##__VA_ARGS__) 84 #define RESSCHED_LOGW(...) RESSCHED_LOG(ResschedLogLevel::WARN, Warn, ##__VA_ARGS__) 85 #define RESSCHED_LOGI(...) RESSCHED_LOG(ResschedLogLevel::INFO, Info, ##__VA_ARGS__) 86 #define RESSCHED_LOGD(...) RESSCHED_LOG(ResschedLogLevel::DEBUG, Debug, ##__VA_ARGS__) 87 } // namespace ResourceSchedule 88 } // namespace OHOS 89 90 #endif // RESSCHED_COMMON_INCLUDE_RES_SCHED_LOG_H 91