1 /* 2 * Copyright (c) 2021-2024 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 #include <cstring> 22 23 namespace OHOS { 24 namespace NetManagerStandard { 25 enum class NetMgrExtLogLevel { 26 DEBUG = 0, 27 INFO, 28 WARN, 29 ERROR, 30 FATAL, 31 }; 32 33 class NetMgrExtLogWrapper { 34 public: 35 static bool JudgeLevel(const NetMgrExtLogLevel &level); 36 SetLogLevel(const NetMgrExtLogLevel & level)37 static void SetLogLevel(const NetMgrExtLogLevel &level) 38 { 39 level_ = level; 40 } 41 GetLogLevel()42 static const NetMgrExtLogLevel &GetLogLevel() 43 { 44 return level_; 45 } 46 47 static std::string GetBriefFileName(const std::string &file); 48 49 private: 50 static NetMgrExtLogLevel level_; 51 }; 52 53 #ifndef NETMGR_EXT_LOG_TAG 54 #define NETMGR_EXT_LOG_TAG "NetMgrExtPart" 55 #endif 56 57 #undef LOG_TAG 58 #define LOG_TAG NETMGR_EXT_LOG_TAG 59 60 #define NETMANAGER_EXT_LOG_DOMAIN 0xD0015B0 61 62 #undef LOG_DOMAIN 63 #define LOG_DOMAIN NETMANAGER_EXT_LOG_DOMAIN 64 65 #define NETMGR_EXT_DEBUG 1 66 67 #define MAKE_FILE_NAME (strrchr(__FILE__, '/') + 1) 68 69 #ifdef NETMGR_EXT_DEBUG 70 #define PRINT_LOG(op, fmt, ...) \ 71 (void)HILOG_IMPL(LOG_CORE, LOG_##op, LOG_DOMAIN, LOG_TAG, "[%{public}s:%{public}d]" fmt, \ 72 MAKE_FILE_NAME, __LINE__, ##__VA_ARGS__) 73 #else 74 #define PRINT_LOG(op, fmt, ...) 75 #endif 76 77 #define NETMGR_EXT_LOG_D(fmt, ...) PRINT_LOG(DEBUG, fmt, ##__VA_ARGS__) 78 #define NETMGR_EXT_LOG_E(fmt, ...) PRINT_LOG(ERROR, fmt, ##__VA_ARGS__) 79 #define NETMGR_EXT_LOG_W(fmt, ...) PRINT_LOG(WARN, fmt, ##__VA_ARGS__) 80 #define NETMGR_EXT_LOG_I(fmt, ...) PRINT_LOG(INFO, fmt, ##__VA_ARGS__) 81 #define NETMGR_EXT_LOG_F(fmt, ...) PRINT_LOG(FATAL, fmt, ##__VA_ARGS__) 82 } // namespace NetManagerStandard 83 } // namespace OHOS 84 #endif // NETMGR_EXT_LOG_WRAPPER_H 85