• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 NETMGR_LOG_WRAPPER_H
17 #define NETMGR_LOG_WRAPPER_H
18 
19 #include "hilog/log.h"
20 #include <cstring>
21 #include <string>
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
25 enum class NetMgrLogLevel {
26     DEBUG = 0,
27     INFO,
28     WARN,
29     ERROR,
30     FATAL,
31 };
32 
33 class NetMgrLogWrapper {
34 public:
35     static bool JudgeLevel(const NetMgrLogLevel &level);
36 
SetLogLevel(const NetMgrLogLevel & level)37     static void SetLogLevel(const NetMgrLogLevel &level)
38     {
39         level_ = level;
40     }
41 
GetLogLevel()42     static const NetMgrLogLevel &GetLogLevel()
43     {
44         return level_;
45     }
46 
47     static std::string GetBriefFileName(const std::string &file);
48 
49 private:
50     static NetMgrLogLevel level_;
51 };
52 
53 #ifndef NETMGR_LOG_TAG
54 #define NETMGR_LOG_TAG "NetMgrSubsystem"
55 #endif
56 
57 static constexpr OHOS::HiviewDFX::HiLogLabel NET_MGR_LABEL = {LOG_CORE, LOG_DOMAIN, NETMGR_LOG_TAG};
58 
59 #ifdef NETMGR_DEBUG
60 #define MAKE_FILE_NAME (strrchr(__FILE__, '/') + 1)
61 #define PRINT_LOG(op, fmt, ...)                                                                               \
62     (void)OHOS::HiviewDFX::HiLog::op(NET_MGR_LABEL, "[%{public}s-(%{public}s:%{public}d)]" fmt, __FUNCTION__, \
63                                      MAKE_FILE_NAME, __LINE__, ##__VA_ARGS__)
64 #else
65 #define PRINT_LOG(op, fmt, ...)
66 #endif
67 
68 #define NETMGR_LOG_D(fmt, ...) PRINT_LOG(Debug, fmt, ##__VA_ARGS__)
69 #define NETMGR_LOG_E(fmt, ...) PRINT_LOG(Error, fmt, ##__VA_ARGS__)
70 #define NETMGR_LOG_W(fmt, ...) PRINT_LOG(Warn, fmt, ##__VA_ARGS__)
71 #define NETMGR_LOG_I(fmt, ...) PRINT_LOG(Info, fmt, ##__VA_ARGS__)
72 #define NETMGR_LOG_F(fmt, ...) PRINT_LOG(Fatal, fmt, ##__VA_ARGS__)
73 } // namespace NetManagerStandard
74 } // namespace OHOS
75 #endif // NETMGR_LOG_WRAPPER_H