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_DISC_LOG_H
17 #define DSOFTBUS_DISC_LOG_H
18 
19 #include "softbus_log.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 typedef enum {
25     DISC_INIT,
26     DISC_CONTROL,
27     DISC_LNN,
28     DISC_BLE,
29     DISC_BLE_ADAPTER,
30     DISC_COAP,
31     DISC_DFINDER,
32     DISC_ABILITY,
33     DISC_USB,
34     DISC_USB_ADAPTER,
35     DISC_SDK,
36     DISC_BROADCAST,
37     DISC_TEST,
38 } DiscLogLabelEnum;
39 
40 /* Keep consistent with labels */
41 static const SoftBusLogLabel DISC_LABELS[MODULE_DOMAIN_MAX_LEN] = {
42     { DISC_INIT,        0xd0057a0,      "DiscInit"      },
43     { DISC_CONTROL,     0xd0057a1,      "DiscControl"   },
44     { DISC_LNN,         0xd0057a2,      "DiscLnn"       },
45     { DISC_BLE,         0xd0057a3,      "DiscBle"       },
46     { DISC_BLE_ADAPTER, 0xd0057a4,      "DiscBleAdapter"},
47     { DISC_COAP,        0xd0057a5,      "DiscCoap"      },
48     { DISC_DFINDER,     0xd0057a6,      "DiscDfinder"   },
49     { DISC_ABILITY,     0xd0057a7,      "DiscAbility"   },
50     { DISC_USB,         0xd0057a8,      "DiscUsb"       },
51     { DISC_USB_ADAPTER, 0xd0057a9,      "DiscUsbAdapter"},
52     { DISC_SDK,         0xd0057aa,      "DiscSdk"       },
53     { DISC_BROADCAST,   0xd0057ab,      "DiscBroadcast" },
54     { DISC_TEST,        DOMAIN_ID_TEST, "DiscTest"      },
55 };
56 
57 #if defined(SOFTBUS_LITEOS_M)
58 #define DISC_LOGF(label, fmt, ...) SOFTBUS_LOGF_INNER(label, fmt, ##__VA_ARGS__)
59 #define DISC_LOGE(label, fmt, ...) SOFTBUS_LOGE_INNER(label, fmt, ##__VA_ARGS__)
60 #define DISC_LOGW(label, fmt, ...) SOFTBUS_LOGW_INNER(label, fmt, ##__VA_ARGS__)
61 #define DISC_LOGI(label, fmt, ...) SOFTBUS_LOGI_INNER(label, fmt, ##__VA_ARGS__)
62 #define DISC_LOGD(label, fmt, ...) SOFTBUS_LOGD_INNER(label, fmt, ##__VA_ARGS__)
63 #else
64 #define DISC_LOGF(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_FATAL, DISC_LABELS[label], fmt, ##__VA_ARGS__)
65 #define DISC_LOGE(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_ERROR, DISC_LABELS[label], fmt, ##__VA_ARGS__)
66 #define DISC_LOGW(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_WARN, DISC_LABELS[label], fmt, ##__VA_ARGS__)
67 #define DISC_LOGI(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_INFO, DISC_LABELS[label], fmt, ##__VA_ARGS__)
68 #define DISC_LOGD(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_DEBUG, DISC_LABELS[label], fmt, ##__VA_ARGS__)
69 #endif // SOFTBUS_LITEOS_M
70 
71 #define DISC_CHECK_AND_RETURN_RET_LOGD(cond, ret, label, fmt, ...) \
72     CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, DISC_LOGD, label, fmt, ##__VA_ARGS__)
73 #define DISC_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
74     CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, DISC_LOGW, label, fmt, ##__VA_ARGS__)
75 #define DISC_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \
76     CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, DISC_LOGE, label, fmt, ##__VA_ARGS__)
77 #define DISC_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
78     CHECK_AND_RETURN_LOG_INNER(cond, DISC_LOGD, label, fmt, ##__VA_ARGS__)
79 #define DISC_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \
80     CHECK_AND_RETURN_LOG_INNER(cond, DISC_LOGW, label, fmt, ##__VA_ARGS__)
81 #define DISC_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
82     CHECK_AND_RETURN_LOG_INNER(cond, DISC_LOGE, label, fmt, ##__VA_ARGS__)
83 
84 #ifdef __cplusplus
85 }
86 #endif
87 #endif // DSOFTBUS_DISC_LOG_H
88