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_TRANS_LOG_H
17 #define DSOFTBUS_TRANS_LOG_H
18 
19 #include "anonymizer.h"
20 #include "softbus_log.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 typedef enum {
26     TRANS_SDK,
27     TRANS_SVC,
28     TRANS_INIT,
29     TRANS_CTRL,
30     TRANS_BYTES,
31     TRANS_FILE,
32     TRANS_MSG,
33     TRANS_STREAM,
34     TRANS_QOS,
35     TRANS_TEST,
36 } TransLogLabelEnum;
37 
38 /* Keep consistent with labels */
39 static const SoftBusLogLabel TRANS_LABELS[MODULE_DOMAIN_MAX_LEN] = {
40     { TRANS_SDK,    0xd005740,      "TransSdk"   },
41     { TRANS_SVC,    0xd005741,      "TransSvc"   },
42     { TRANS_INIT,   0xd005742,      "TransInit"  },
43     { TRANS_CTRL,   0xd005743,      "TransCtrl"  },
44     { TRANS_BYTES,  0xd005744,      "TransBytes" },
45     { TRANS_FILE,   0xd005745,      "TransFile"  },
46     { TRANS_MSG,    0xd005746,      "TransMsg"   },
47     { TRANS_STREAM, 0xd005747,      "TransStream"},
48     { TRANS_QOS,    0xd005748,      "TransQos"   },
49     { TRANS_TEST,   DOMAIN_ID_TEST, "TransTest"  },
50 };
51 
52 #if defined(SOFTBUS_LITEOS_M)
53 #define TRANS_LOGF(label, fmt, ...) SOFTBUS_LOGF_INNER(label, fmt, ##__VA_ARGS__)
54 #define TRANS_LOGE(label, fmt, ...) SOFTBUS_LOGE_INNER(label, fmt, ##__VA_ARGS__)
55 #define TRANS_LOGW(label, fmt, ...) SOFTBUS_LOGW_INNER(label, fmt, ##__VA_ARGS__)
56 #define TRANS_LOGI(label, fmt, ...) SOFTBUS_LOGI_INNER(label, fmt, ##__VA_ARGS__)
57 #define TRANS_LOGD(label, fmt, ...) SOFTBUS_LOGD_INNER(label, fmt, ##__VA_ARGS__)
58 #else
59 #define TRANS_LOGF(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_FATAL, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
60 #define TRANS_LOGE(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_ERROR, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
61 #define TRANS_LOGW(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_WARN, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
62 #define TRANS_LOGI(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_INFO, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
63 #define TRANS_LOGD(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_DEBUG, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
64 #endif // SOFTBUS_LITEOS_M
65 
66 #define TRANS_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
67     CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, TRANS_LOGW, label, fmt, ##__VA_ARGS__)
68 #define TRANS_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \
69     CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, TRANS_LOGE, label, fmt, ##__VA_ARGS__)
70 #define TRANS_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \
71     CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGW, label, fmt, ##__VA_ARGS__)
72 #define TRANS_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
73     CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGE, label, fmt, ##__VA_ARGS__)
74 #define TRANS_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
75     CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGD, label, fmt, ##__VA_ARGS__)
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 #endif // DSOFTBUS_TRANS_LOG_H
81