1 /* 2 * Copyright (c) 2025 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 COMMUNICATIONNETMANAGER_BASE_NETMANAGER_BASE_LOG 17 #define COMMUNICATIONNETMANAGER_BASE_NETMANAGER_BASE_LOG 18 #include "hilog/log.h" 19 #include <string.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #undef LOG_TAG 26 #ifndef NETMGR_LOG_TAG 27 #define LOG_TAG "NetMgrSubSystem" 28 #else 29 #define LOG_TAG NETMGR_LOG_TAG 30 #endif 31 #undef LOG_DOMAIN 32 #define LOG_DOMAIN 0xD0015B0 33 34 // 日志宏主体,不额外输出源代码位置和函数名 35 #define NETMANAGER_LOG(Level, fmt, ...) \ 36 (void)HILOG_IMPL(LOG_CORE, LOG_##Level, LOG_DOMAIN, LOG_TAG, fmt, ##__VA_ARGS__) 37 38 #define MAKE_FILE_NAME (strrchr(__FILE__, '/') + 1) 39 40 // 日志宏函数,添加日志所在的源代码文件名和行号 41 #define NETMANAGER_LOG_CODELINE(Level, fmt, ...) \ 42 do { \ 43 (void)HILOG_IMPL(LOG_CORE, LOG_##Level, LOG_DOMAIN, LOG_TAG, "[%{public}s:%{public}d]" fmt, MAKE_FILE_NAME, \ 44 __LINE__, ##__VA_ARGS__); \ 45 } while (0) 46 47 // 日志宏函数,添加日志所在的函数名 48 #define NETMANAGER_LOG_FUNC(Level, fmt, ...) \ 49 do { \ 50 (void)HILOG_IMPL(LOG_CORE, LOG_##Level, LOG_DOMAIN, LOG_TAG, "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__); \ 51 } while (0) 52 53 // 简化接口(DEBUG级别对应空宏) 54 #define NETMANAGER_BASE_LOGE(fmt, ...) NETMANAGER_LOG(ERROR, fmt, ##__VA_ARGS__) 55 #define NETMANAGER_BASE_LOGI(fmt, ...) NETMANAGER_LOG(INFO, fmt, ##__VA_ARGS__) 56 #define NETMANAGER_BASE_LOGW(fmt, ...) NETMANAGER_LOG(WARN, fmt, ##__VA_ARGS__) 57 #define NETMANAGER_BASE_LOGD(fmt, ...) ((void)(0, ##__VA_ARGS__)) 58 59 #define NETMGR_LOG_D(fmt, ...) ((void)(0, ##__VA_ARGS__)) 60 #define NETMGR_LOG_E(fmt, ...) NETMANAGER_LOG(ERROR, fmt, ##__VA_ARGS__) 61 #define NETMGR_LOG_W(fmt, ...) NETMANAGER_LOG(WARN, fmt, ##__VA_ARGS__) 62 #define NETMGR_LOG_I(fmt, ...) NETMANAGER_LOG(INFO, fmt, ##__VA_ARGS__) 63 64 #ifdef __cplusplus 65 } 66 #endif 67 68 #endif /* COMMUNICATIONNETMANAGER_BASE_NETMANAGER_BASE_LOG */ 69