DPDK  18.02.2
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 
24 #include <rte_common.h>
25 #include <rte_config.h>
26 
27 struct rte_log_dynamic_type;
28 
30 struct rte_logs {
31  uint32_t type;
32  uint32_t level;
33  FILE *file;
34  size_t dynamic_types_len;
35  struct rte_log_dynamic_type *dynamic_types;
36 };
37 
39 extern struct rte_logs rte_logs;
40 
41 /* SDK log type */
42 #define RTE_LOGTYPE_EAL 0
43 #define RTE_LOGTYPE_MALLOC 1
44 #define RTE_LOGTYPE_RING 2
45 #define RTE_LOGTYPE_MEMPOOL 3
46 #define RTE_LOGTYPE_TIMER 4
47 #define RTE_LOGTYPE_PMD 5
48 #define RTE_LOGTYPE_HASH 6
49 #define RTE_LOGTYPE_LPM 7
50 #define RTE_LOGTYPE_KNI 8
51 #define RTE_LOGTYPE_ACL 9
52 #define RTE_LOGTYPE_POWER 10
53 #define RTE_LOGTYPE_METER 11
54 #define RTE_LOGTYPE_SCHED 12
55 #define RTE_LOGTYPE_PORT 13
56 #define RTE_LOGTYPE_TABLE 14
57 #define RTE_LOGTYPE_PIPELINE 15
58 #define RTE_LOGTYPE_MBUF 16
59 #define RTE_LOGTYPE_CRYPTODEV 17
60 #define RTE_LOGTYPE_EFD 18
61 #define RTE_LOGTYPE_EVENTDEV 19
62 #define RTE_LOGTYPE_GSO 20
64 /* these log types can be used in an application */
65 #define RTE_LOGTYPE_USER1 24
66 #define RTE_LOGTYPE_USER2 25
67 #define RTE_LOGTYPE_USER3 26
68 #define RTE_LOGTYPE_USER4 27
69 #define RTE_LOGTYPE_USER5 28
70 #define RTE_LOGTYPE_USER6 29
71 #define RTE_LOGTYPE_USER7 30
72 #define RTE_LOGTYPE_USER8 31
75 #define RTE_LOGTYPE_FIRST_EXT_ID 32
76 
77 /* Can't use 0, as it gives compiler warnings */
78 #define RTE_LOG_EMERG 1U
79 #define RTE_LOG_ALERT 2U
80 #define RTE_LOG_CRIT 3U
81 #define RTE_LOG_ERR 4U
82 #define RTE_LOG_WARNING 5U
83 #define RTE_LOG_NOTICE 6U
84 #define RTE_LOG_INFO 7U
85 #define RTE_LOG_DEBUG 8U
100 int rte_openlog_stream(FILE *f);
101 
111 void rte_log_set_global_level(uint32_t level);
112 
119 uint32_t rte_log_get_global_level(void);
120 
129 int rte_log_get_level(uint32_t logtype);
130 
141 int rte_log_set_level_regexp(const char *pattern, uint32_t level);
142 
153 int rte_log_set_level(uint32_t logtype, uint32_t level);
154 
167 int rte_log_cur_msg_loglevel(void);
168 
181 int rte_log_cur_msg_logtype(void);
182 
195 int rte_log_register(const char *name);
196 
205 void rte_log_dump(FILE *f);
206 
230 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
231 #ifdef __GNUC__
232 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
233  __attribute__((cold))
234 #endif
235 #endif
236  __attribute__((format(printf, 3, 4)));
237 
264 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
265  __attribute__((format(printf,3,0)));
266 
286 #define RTE_LOG(l, t, ...) \
287  rte_log(RTE_LOG_ ## l, \
288  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
289 
310 #define RTE_LOG_DP(l, t, ...) \
311  (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ? \
312  rte_log(RTE_LOG_ ## l, \
313  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
314  0)
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 
320 #endif /* _RTE_LOG_H_ */