DPDK  20.11.10
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 <stdbool.h>
24 #include <sys/queue.h>
25 
26 #include <rte_common.h>
27 #include <rte_config.h>
28 #include <rte_compat.h>
29 
30 /* SDK log type */
31 #define RTE_LOGTYPE_EAL 0
32 #define RTE_LOGTYPE_MALLOC 1
33 #define RTE_LOGTYPE_RING 2
34 #define RTE_LOGTYPE_MEMPOOL 3
35 #define RTE_LOGTYPE_TIMER 4
36 #define RTE_LOGTYPE_PMD 5
37 #define RTE_LOGTYPE_HASH 6
38 #define RTE_LOGTYPE_LPM 7
39 #define RTE_LOGTYPE_KNI 8
40 #define RTE_LOGTYPE_ACL 9
41 #define RTE_LOGTYPE_POWER 10
42 #define RTE_LOGTYPE_METER 11
43 #define RTE_LOGTYPE_SCHED 12
44 #define RTE_LOGTYPE_PORT 13
45 #define RTE_LOGTYPE_TABLE 14
46 #define RTE_LOGTYPE_PIPELINE 15
47 #define RTE_LOGTYPE_MBUF 16
48 #define RTE_LOGTYPE_CRYPTODEV 17
49 #define RTE_LOGTYPE_EFD 18
50 #define RTE_LOGTYPE_EVENTDEV 19
51 #define RTE_LOGTYPE_GSO 20
53 /* these log types can be used in an application */
54 #define RTE_LOGTYPE_USER1 24
55 #define RTE_LOGTYPE_USER2 25
56 #define RTE_LOGTYPE_USER3 26
57 #define RTE_LOGTYPE_USER4 27
58 #define RTE_LOGTYPE_USER5 28
59 #define RTE_LOGTYPE_USER6 29
60 #define RTE_LOGTYPE_USER7 30
61 #define RTE_LOGTYPE_USER8 31
64 #define RTE_LOGTYPE_FIRST_EXT_ID 32
65 
66 /* Can't use 0, as it gives compiler warnings */
67 #define RTE_LOG_EMERG 1U
68 #define RTE_LOG_ALERT 2U
69 #define RTE_LOG_CRIT 3U
70 #define RTE_LOG_ERR 4U
71 #define RTE_LOG_WARNING 5U
72 #define RTE_LOG_NOTICE 6U
73 #define RTE_LOG_INFO 7U
74 #define RTE_LOG_DEBUG 8U
89 int rte_openlog_stream(FILE *f);
90 
98 FILE *rte_log_get_stream(void);
99 
109 void rte_log_set_global_level(uint32_t level);
110 
117 uint32_t rte_log_get_global_level(void);
118 
127 int rte_log_get_level(uint32_t logtype);
128 
139 __rte_experimental
140 bool rte_log_can_log(uint32_t logtype, uint32_t loglevel);
141 
152 int rte_log_set_level_pattern(const char *pattern, uint32_t level);
153 
164 int rte_log_set_level_regexp(const char *regex, uint32_t level);
165 
176 int rte_log_set_level(uint32_t logtype, uint32_t level);
177 
190 int rte_log_cur_msg_loglevel(void);
191 
204 int rte_log_cur_msg_logtype(void);
205 
218 int rte_log_register(const char *name);
219 
239 __rte_experimental
240 int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
241 
250 void rte_log_dump(FILE *f);
251 
275 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
276 #ifdef __GNUC__
277 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
278  __rte_cold
279 #endif
280 #endif
281  __rte_format_printf(3, 4);
282 
309 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
310  __rte_format_printf(3, 0);
311 
331 #define RTE_LOG(l, t, ...) \
332  rte_log(RTE_LOG_ ## l, \
333  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
334 
355 #define RTE_LOG_DP(l, t, ...) \
356  (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ? \
357  rte_log(RTE_LOG_ ## l, \
358  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
359  0)
360 
377 #define RTE_LOG_REGISTER(type, name, level) \
378 int type; \
379 RTE_INIT(__##type) \
380 { \
381  type = rte_log_register_type_and_pick_level(RTE_STR(name), \
382  RTE_LOG_##level); \
383 }
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 
389 #endif /* _RTE_LOG_H_ */
int rte_log_set_level_pattern(const char *pattern, uint32_t level)
int rte_log_set_level_regexp(const char *regex, uint32_t level)
__rte_experimental int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
#define __rte_cold
Definition: rte_common.h:246
int rte_log_set_level(uint32_t logtype, uint32_t level)
void rte_log_dump(FILE *f)
#define __rte_format_printf(format_index, first_arg)
Definition: rte_common.h:149
uint32_t rte_log_get_global_level(void)
int rte_log(uint32_t level, uint32_t logtype, const char *format,...) __rte_format_printf(3
int rte_log_cur_msg_logtype(void)
__rte_experimental bool rte_log_can_log(uint32_t logtype, uint32_t loglevel)
FILE * rte_log_get_stream(void)
int rte_log_get_level(uint32_t logtype)
void rte_log_set_global_level(uint32_t level)
int int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) __rte_format_printf(3
int rte_log_register(const char *name)
int rte_log_cur_msg_loglevel(void)