122c0b7e4Sopenharmony_ci/* 222c0b7e4Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 322c0b7e4Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 422c0b7e4Sopenharmony_ci * you may not use this file except in compliance with the License. 522c0b7e4Sopenharmony_ci * You may obtain a copy of the License at 622c0b7e4Sopenharmony_ci * 722c0b7e4Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 822c0b7e4Sopenharmony_ci * 922c0b7e4Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1022c0b7e4Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1122c0b7e4Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1222c0b7e4Sopenharmony_ci * See the License for the specific language governing permissions and 1322c0b7e4Sopenharmony_ci * limitations under the License. 1422c0b7e4Sopenharmony_ci */ 1522c0b7e4Sopenharmony_ci 1622c0b7e4Sopenharmony_ci#ifndef BUNDLE_ACTIVE_LOG_H 1722c0b7e4Sopenharmony_ci#define BUNDLE_ACTIVE_LOG_H 1822c0b7e4Sopenharmony_ci 1922c0b7e4Sopenharmony_ci#include <string> 2022c0b7e4Sopenharmony_ci#include "hilog/log.h" 2122c0b7e4Sopenharmony_ci 2222c0b7e4Sopenharmony_cinamespace OHOS { 2322c0b7e4Sopenharmony_cinamespace DeviceUsageStats { 2422c0b7e4Sopenharmony_ci#undef LOG_DOMAIN 2522c0b7e4Sopenharmony_ci#define LOG_DOMAIN 0xD001710 2622c0b7e4Sopenharmony_ci 2722c0b7e4Sopenharmony_ci#undef LOG_TAG 2822c0b7e4Sopenharmony_ci#define LOG_TAG "BUNDLE_ACTIVE" 2922c0b7e4Sopenharmony_ci 3022c0b7e4Sopenharmony_cienum class BundleActiveLogLevel : uint8_t { DEBUG = 0, INFO, WARN, ERROR, FATAL }; 3122c0b7e4Sopenharmony_ci 3222c0b7e4Sopenharmony_ciclass BundleActiveLog { 3322c0b7e4Sopenharmony_cipublic: 3422c0b7e4Sopenharmony_ci BundleActiveLog() = delete; 3522c0b7e4Sopenharmony_ci ~BundleActiveLog() = delete; 3622c0b7e4Sopenharmony_ci 3722c0b7e4Sopenharmony_ci static bool JudgeValidLevel(const BundleActiveLogLevel &level); 3822c0b7e4Sopenharmony_ci 3922c0b7e4Sopenharmony_ci static void SetLogLevel(const BundleActiveLogLevel &level) 4022c0b7e4Sopenharmony_ci { 4122c0b7e4Sopenharmony_ci logLevel_ = level; 4222c0b7e4Sopenharmony_ci } 4322c0b7e4Sopenharmony_ci 4422c0b7e4Sopenharmony_ci static const BundleActiveLogLevel &GetLogLevel() 4522c0b7e4Sopenharmony_ci { 4622c0b7e4Sopenharmony_ci return logLevel_; 4722c0b7e4Sopenharmony_ci } 4822c0b7e4Sopenharmony_ci 4922c0b7e4Sopenharmony_ci static std::string GetCurrFileName(const char *str); 5022c0b7e4Sopenharmony_ci 5122c0b7e4Sopenharmony_ciprivate: 5222c0b7e4Sopenharmony_ci static BundleActiveLogLevel logLevel_; 5322c0b7e4Sopenharmony_ci}; 5422c0b7e4Sopenharmony_ci 5522c0b7e4Sopenharmony_ci#define BUNDLE_ACTIVE_LOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \ 5622c0b7e4Sopenharmony_ci BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__) 5722c0b7e4Sopenharmony_ci#define BUNDLE_ACTIVE_LOGI(fmt, ...) HILOG_INFO(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \ 5822c0b7e4Sopenharmony_ci BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__) 5922c0b7e4Sopenharmony_ci#define BUNDLE_ACTIVE_LOGW(fmt, ...) HILOG_WARN(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \ 6022c0b7e4Sopenharmony_ci BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__) 6122c0b7e4Sopenharmony_ci#define BUNDLE_ACTIVE_LOGE(fmt, ...) HILOG_ERROR(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \ 6222c0b7e4Sopenharmony_ci BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__) 6322c0b7e4Sopenharmony_ci#define BUNDLE_ACTIVE_LOGF(fmt, ...) HILOG_FATAL(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \ 6422c0b7e4Sopenharmony_ci BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__) 6522c0b7e4Sopenharmony_ci} // namespace DeviceUsageStats 6622c0b7e4Sopenharmony_ci} // namespace OHOS 6722c0b7e4Sopenharmony_ci#endif // BUNDLE_ACTIVE_LOG_H 6822c0b7e4Sopenharmony_ci 69