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_EXT_LOG_WRAPPER_H 17 #define NETMGR_EXT_LOG_WRAPPER_H 18 19 #include <string> 20 #include "hilog/log.h" 21 22 namespace OHOS { 23 namespace NetManagerStandard { 24 enum class NetMgrExtLogLevel { 25 DEBUG = 0, 26 INFO, 27 WARN, 28 ERROR, 29 FATAL, 30 }; 31 32 class NetMgrExtLogWrapper { 33 public: 34 static bool JudgeLevel(const NetMgrExtLogLevel &level); 35 SetLogLevel(const NetMgrExtLogLevel & level)36 static void SetLogLevel(const NetMgrExtLogLevel &level) 37 { 38 level_ = level; 39 } 40 GetLogLevel()41 static const NetMgrExtLogLevel &GetLogLevel() 42 { 43 return level_; 44 } 45 46 static std::string GetBriefFileName(const std::string &file); 47 48 private: 49 static NetMgrExtLogLevel level_; 50 }; 51 52 #ifndef NETMGR_EXT_LOG_TAG 53 #define NETMGR_EXT_LOG_TAG "NetMgrExtPart" 54 #endif 55 56 static constexpr OHOS::HiviewDFX::HiLogLabel NET_MGR_LABEL = {LOG_CORE, LOG_DOMAIN, NETMGR_EXT_LOG_TAG}; 57 58 #define NETMGR_EXT_DEBUG 1 59 60 #ifdef NETMGR_EXT_DEBUG 61 #define PRINT_LOG(op, fmt, ...) \ 62 (void)OHOS::HiviewDFX::HiLog::op(NET_MGR_LABEL, "[%{public}s-(%{public}s:%{public}d)]" fmt, __FUNCTION__, \ 63 __FILE__, __LINE__, ##__VA_ARGS__) 64 #else 65 #define PRINT_LOG(op, fmt, ...) 66 #endif 67 68 #define NETMGR_EXT_LOG_D(fmt, ...) PRINT_LOG(Debug, fmt, ##__VA_ARGS__) 69 #define NETMGR_EXT_LOG_E(fmt, ...) PRINT_LOG(Error, fmt, ##__VA_ARGS__) 70 #define NETMGR_EXT_LOG_W(fmt, ...) PRINT_LOG(Warn, fmt, ##__VA_ARGS__) 71 #define NETMGR_EXT_LOG_I(fmt, ...) PRINT_LOG(Info, fmt, ##__VA_ARGS__) 72 #define NETMGR_EXT_LOG_F(fmt, ...) PRINT_LOG(Fatal, fmt, ##__VA_ARGS__) 73 } // namespace NetManagerStandard 74 } // namespace OHOS 75 #endif // NETMGR_EXT_LOG_WRAPPER_H