DPDK  19.05.0
rte_log.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4 
5 #ifndef _RTE_LOG_H_
6 #define _RTE_LOG_H_
7 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <sys/queue.h>
24 
25 #include <rte_common.h>
26 #include <rte_config.h>
27 #include <rte_compat.h>
28 
29 struct rte_log_dynamic_type;
30 
32 struct rte_logs {
33  uint32_t type;
34  uint32_t level;
35  FILE *file;
36  size_t dynamic_types_len;
37  struct rte_log_dynamic_type *dynamic_types;
38 };
39 
41 extern struct rte_logs rte_logs;
42 
43 /* SDK log type */
44 #define RTE_LOGTYPE_EAL 0
45 #define RTE_LOGTYPE_MALLOC 1
46 #define RTE_LOGTYPE_RING 2
47 #define RTE_LOGTYPE_MEMPOOL 3
48 #define RTE_LOGTYPE_TIMER 4
49 #define RTE_LOGTYPE_PMD 5
50 #define RTE_LOGTYPE_HASH 6
51 #define RTE_LOGTYPE_LPM 7
52 #define RTE_LOGTYPE_KNI 8
53 #define RTE_LOGTYPE_ACL 9
54 #define RTE_LOGTYPE_POWER 10
55 #define RTE_LOGTYPE_METER 11
56 #define RTE_LOGTYPE_SCHED 12
57 #define RTE_LOGTYPE_PORT 13
58 #define RTE_LOGTYPE_TABLE 14
59 #define RTE_LOGTYPE_PIPELINE 15
60 #define RTE_LOGTYPE_MBUF 16
61 #define RTE_LOGTYPE_CRYPTODEV 17
62 #define RTE_LOGTYPE_EFD 18
63 #define RTE_LOGTYPE_EVENTDEV 19
64 #define RTE_LOGTYPE_GSO 20
66 /* these log types can be used in an application */
67 #define RTE_LOGTYPE_USER1 24
68 #define RTE_LOGTYPE_USER2 25
69 #define RTE_LOGTYPE_USER3 26
70 #define RTE_LOGTYPE_USER4 27
71 #define RTE_LOGTYPE_USER5 28
72 #define RTE_LOGTYPE_USER6 29
73 #define RTE_LOGTYPE_USER7 30
74 #define RTE_LOGTYPE_USER8 31
77 #define RTE_LOGTYPE_FIRST_EXT_ID 32
78 
79 /* Can't use 0, as it gives compiler warnings */
80 #define RTE_LOG_EMERG 1U
81 #define RTE_LOG_ALERT 2U
82 #define RTE_LOG_CRIT 3U
83 #define RTE_LOG_ERR 4U
84 #define RTE_LOG_WARNING 5U
85 #define RTE_LOG_NOTICE 6U
86 #define RTE_LOG_INFO 7U
87 #define RTE_LOG_DEBUG 8U
102 int rte_openlog_stream(FILE *f);
103 
113 void rte_log_set_global_level(uint32_t level);
114 
121 uint32_t rte_log_get_global_level(void);
122 
131 int rte_log_get_level(uint32_t logtype);
132 
143 int rte_log_set_level_pattern(const char *pattern, uint32_t level);
144 
155 int rte_log_set_level_regexp(const char *regex, uint32_t level);
156 
167 int rte_log_set_level(uint32_t logtype, uint32_t level);
168 
181 int rte_log_cur_msg_loglevel(void);
182 
195 int rte_log_cur_msg_logtype(void);
196 
209 int rte_log_register(const char *name);
210 
230 __rte_experimental
231 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
232 
241 void rte_log_dump(FILE *f);
242 
266 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
267 #ifdef __GNUC__
268 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
269  __attribute__((cold))
270 #endif
271 #endif
272  __attribute__((format(printf, 3, 4)));
273 
300 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
301  __attribute__((format(printf,3,0)));
302 
322 #define RTE_LOG(l, t, ...) \
323  rte_log(RTE_LOG_ ## l, \
324  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
325 
346 #define RTE_LOG_DP(l, t, ...) \
347  (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ? \
348  rte_log(RTE_LOG_ ## l, \
349  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
350  0)
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 
356 #endif /* _RTE_LOG_H_ */