1 /* 2 * Copyright (c) 2023 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 DSOFTBUS_COMM_LOG_H 17 #define DSOFTBUS_COMM_LOG_H 18 19 #include "softbus_log.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 typedef enum { 25 COMM_SDK, 26 COMM_SVC, 27 COMM_INIT, 28 COMM_DFX, 29 COMM_EVENT, 30 COMM_VERIFY, 31 COMM_PERM, 32 COMM_UTILS, 33 COMM_ADAPTER, 34 COMM_TEST, 35 } CommLogLabelEnum; 36 37 /* Keep consistent with labels */ 38 static const SoftBusLogLabel COMM_LABELS[MODULE_DOMAIN_MAX_LEN] = { 39 { COMM_SDK, 0xd005700, "CommSdk" }, 40 { COMM_SVC, 0xd005701, "CommSvc" }, 41 { COMM_INIT, 0xd005702, "CommInit" }, 42 { COMM_DFX, 0xd005703, "CommDfx" }, 43 { COMM_EVENT, 0xd005704, "CommEvent" }, 44 { COMM_VERIFY, 0xd005705, "CommVerify" }, 45 { COMM_PERM, 0xd005706, "CommPerm" }, 46 { COMM_UTILS, 0xd005707, "CommUtils" }, 47 { COMM_ADAPTER, 0xd005708, "CommAdapter"}, 48 { COMM_TEST, DOMAIN_ID_TEST, "CommTest" }, 49 }; 50 51 #if defined(SOFTBUS_LITEOS_M) 52 #define COMM_LOGF(label, fmt, ...) SOFTBUS_LOGF_INNER(label, fmt, ##__VA_ARGS__) 53 #define COMM_LOGE(label, fmt, ...) SOFTBUS_LOGE_INNER(label, fmt, ##__VA_ARGS__) 54 #define COMM_LOGW(label, fmt, ...) SOFTBUS_LOGW_INNER(label, fmt, ##__VA_ARGS__) 55 #define COMM_LOGI(label, fmt, ...) SOFTBUS_LOGI_INNER(label, fmt, ##__VA_ARGS__) 56 #define COMM_LOGD(label, fmt, ...) SOFTBUS_LOGD_INNER(label, fmt, ##__VA_ARGS__) 57 #else 58 #define COMM_LOGF(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_FATAL, COMM_LABELS[label], fmt, ##__VA_ARGS__) 59 #define COMM_LOGE(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_ERROR, COMM_LABELS[label], fmt, ##__VA_ARGS__) 60 #define COMM_LOGW(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_WARN, COMM_LABELS[label], fmt, ##__VA_ARGS__) 61 #define COMM_LOGI(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_INFO, COMM_LABELS[label], fmt, ##__VA_ARGS__) 62 #define COMM_LOGD(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_DEBUG, COMM_LABELS[label], fmt, ##__VA_ARGS__) 63 #endif // SOFTBUS_LITEOS_M 64 65 #define COMM_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \ 66 CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, COMM_LOGW, label, fmt, ##__VA_ARGS__) 67 #define COMM_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \ 68 CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, COMM_LOGE, label, fmt, ##__VA_ARGS__) 69 #define COMM_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \ 70 CHECK_AND_RETURN_LOG_INNER(cond, COMM_LOGW, label, fmt, ##__VA_ARGS__) 71 #define COMM_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \ 72 CHECK_AND_RETURN_LOG_INNER(cond, COMM_LOGE, label, fmt, ##__VA_ARGS__) 73 74 #ifdef __cplusplus 75 } 76 #endif 77 #endif // DSOFTBUS_COMM_LOG_H 78