• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EVENT,
36     TRANS_TEST,
37 } TransLogLabelEnum;
38 
39 /* Keep consistent with labels */
40 static const SoftBusLogLabel TRANS_LABELS[MODULE_DOMAIN_MAX_LEN] = {
41     { TRANS_SDK,        0xd005740,      "TransSdk"      },
42     { TRANS_SVC,        0xd005741,      "TransSvc"      },
43     { TRANS_INIT,       0xd005742,      "TransInit"     },
44     { TRANS_CTRL,       0xd005743,      "TransCtrl"     },
45     { TRANS_BYTES,      0xd005744,      "TransBytes"    },
46     { TRANS_FILE,       0xd005745,      "TransFile"     },
47     { TRANS_MSG,        0xd005746,      "TransMsg"      },
48     { TRANS_STREAM,     0xd005747,      "TransStream"   },
49     { TRANS_QOS,        0xd005748,      "TransQos"      },
50     { TRANS_EVENT,      0xd005749,      "TransEvent"    },
51     { TRANS_TEST,       DOMAIN_ID_TEST, "TransTest"     },
52 };
53 
54 #if defined(SOFTBUS_LITEOS_M)
55 #define TRANS_LOGF(label, fmt, ...) SOFTBUS_LOGF_INNER(label, fmt, ##__VA_ARGS__)
56 #define TRANS_LOGE(label, fmt, ...) SOFTBUS_LOGE_INNER(label, fmt, ##__VA_ARGS__)
57 #define TRANS_LOGW(label, fmt, ...) SOFTBUS_LOGW_INNER(label, fmt, ##__VA_ARGS__)
58 #define TRANS_LOGI(label, fmt, ...) SOFTBUS_LOGI_INNER(label, fmt, ##__VA_ARGS__)
59 #define TRANS_LOGD(label, fmt, ...) SOFTBUS_LOGD_INNER(label, fmt, ##__VA_ARGS__)
60 #else
61 #define TRANS_LOGF(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_FATAL, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
62 #define TRANS_LOGE(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_ERROR, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
63 #define TRANS_LOGW(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_WARN, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
64 #define TRANS_LOGI(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_INFO, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
65 #define TRANS_LOGD(label, fmt, ...) SOFTBUS_LOG_INNER(LOG_DEBUG, TRANS_LABELS[label], fmt, ##__VA_ARGS__)
66 #endif // SOFTBUS_LITEOS_M
67 
68 #define TRANS_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \
69     CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, TRANS_LOGW, label, fmt, ##__VA_ARGS__)
70 #define TRANS_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \
71     CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, TRANS_LOGE, label, fmt, ##__VA_ARGS__)
72 #define TRANS_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \
73     CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGW, label, fmt, ##__VA_ARGS__)
74 #define TRANS_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \
75     CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGE, label, fmt, ##__VA_ARGS__)
76 #define TRANS_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \
77     CHECK_AND_RETURN_LOG_INNER(cond, TRANS_LOGD, label, fmt, ##__VA_ARGS__)
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 #endif // DSOFTBUS_TRANS_LOG_H
83