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 "hilog/log.h" 20 #include <string> 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 #undef LOG_TAG 57 #define LOG_TAG NETMGR_EXT_LOG_TAG 58 59 #define NETMANAGER_EXT_LOG_DOMAIN 0xD0015B0 60 61 #undef LOG_DOMAIN 62 #define LOG_DOMAIN NETMANAGER_EXT_LOG_DOMAIN 63 64 #define NETMGR_EXT_DEBUG 1 65 66 #define MAKE_FILE_NAME (strrchr(__FILE__, '/') + 1) 67 68 #ifdef NETMGR_EXT_DEBUG 69 #define PRINT_LOG(op, fmt, ...) \ 70 (void)HILOG_IMPL(LOG_CORE, LOG_##op, LOG_DOMAIN, LOG_TAG, "[%{public}s-(%{public}s:%{public}d)]" fmt, \ 71 __FUNCTION__, MAKE_FILE_NAME, __LINE__, ##__VA_ARGS__) 72 #else 73 #define PRINT_LOG(op, fmt, ...) 74 #endif 75 76 #define NETMGR_EXT_LOG_D(fmt, ...) PRINT_LOG(DEBUG, fmt, ##__VA_ARGS__) 77 #define NETMGR_EXT_LOG_E(fmt, ...) PRINT_LOG(ERROR, fmt, ##__VA_ARGS__) 78 #define NETMGR_EXT_LOG_W(fmt, ...) PRINT_LOG(WARN, fmt, ##__VA_ARGS__) 79 #define NETMGR_EXT_LOG_I(fmt, ...) PRINT_LOG(INFO, fmt, ##__VA_ARGS__) 80 #define NETMGR_EXT_LOG_F(fmt, ...) PRINT_LOG(FATAL, fmt, ##__VA_ARGS__) 81 } // namespace NetManagerStandard 82 } // namespace OHOS 83 #endif // NETMGR_EXT_LOG_WRAPPER_H 84