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 BUNDLE_ACTIVE_LOG_H
17 #define BUNDLE_ACTIVE_LOG_H
18 
19 #include <string>
20 #include "hilog/log.h"
21 
22 namespace OHOS {
23 namespace DeviceUsageStats {
24 #undef LOG_DOMAIN
25 #define LOG_DOMAIN 0xD001710
26 
27 #undef LOG_TAG
28 #define LOG_TAG "BUNDLE_ACTIVE"
29 
30 enum class BundleActiveLogLevel : uint8_t { DEBUG = 0, INFO, WARN, ERROR, FATAL };
31 
32 class BundleActiveLog {
33 public:
34     BundleActiveLog() = delete;
35     ~BundleActiveLog() = delete;
36 
37     static bool JudgeValidLevel(const BundleActiveLogLevel &level);
38 
SetLogLevel(const BundleActiveLogLevel & level)39     static void SetLogLevel(const BundleActiveLogLevel &level)
40     {
41         logLevel_ = level;
42     }
43 
GetLogLevel()44     static const BundleActiveLogLevel &GetLogLevel()
45     {
46         return logLevel_;
47     }
48 
49     static std::string GetCurrFileName(const char *str);
50 
51 private:
52     static BundleActiveLogLevel logLevel_;
53 };
54 
55 #define BUNDLE_ACTIVE_LOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \
56         BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
57 #define BUNDLE_ACTIVE_LOGI(fmt, ...) HILOG_INFO(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \
58         BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
59 #define BUNDLE_ACTIVE_LOGW(fmt, ...) HILOG_WARN(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \
60         BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
61 #define BUNDLE_ACTIVE_LOGE(fmt, ...) HILOG_ERROR(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \
62         BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
63 #define BUNDLE_ACTIVE_LOGF(fmt, ...) HILOG_FATAL(LOG_CORE, "[%{public}s(%{public}s):%{public}d]" fmt, \
64         BundleActiveLog::GetCurrFileName(__FILE__).c_str(), __FUNCTION__, __LINE__, ##__VA_ARGS__)
65 }  // namespace DeviceUsageStats
66 }  // namespace OHOS
67 #endif  // BUNDLE_ACTIVE_LOG_H
68 
69