DPDK  17.11.10
rte_log.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Intel Corporation nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_LOG_H_
35 #define _RTE_LOG_H_
36 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #include <stdint.h>
50 #include <stdio.h>
51 #include <stdarg.h>
52 
53 #include <rte_common.h>
54 #include <rte_config.h>
55 
56 struct rte_log_dynamic_type;
57 
59 struct rte_logs {
60  uint32_t type;
61  uint32_t level;
62  FILE *file;
63  size_t dynamic_types_len;
64  struct rte_log_dynamic_type *dynamic_types;
65 };
66 
68 extern struct rte_logs rte_logs;
69 
70 /* SDK log type */
71 #define RTE_LOGTYPE_EAL 0
72 #define RTE_LOGTYPE_MALLOC 1
73 #define RTE_LOGTYPE_RING 2
74 #define RTE_LOGTYPE_MEMPOOL 3
75 #define RTE_LOGTYPE_TIMER 4
76 #define RTE_LOGTYPE_PMD 5
77 #define RTE_LOGTYPE_HASH 6
78 #define RTE_LOGTYPE_LPM 7
79 #define RTE_LOGTYPE_KNI 8
80 #define RTE_LOGTYPE_ACL 9
81 #define RTE_LOGTYPE_POWER 10
82 #define RTE_LOGTYPE_METER 11
83 #define RTE_LOGTYPE_SCHED 12
84 #define RTE_LOGTYPE_PORT 13
85 #define RTE_LOGTYPE_TABLE 14
86 #define RTE_LOGTYPE_PIPELINE 15
87 #define RTE_LOGTYPE_MBUF 16
88 #define RTE_LOGTYPE_CRYPTODEV 17
89 #define RTE_LOGTYPE_EFD 18
90 #define RTE_LOGTYPE_EVENTDEV 19
91 #define RTE_LOGTYPE_GSO 20
93 /* these log types can be used in an application */
94 #define RTE_LOGTYPE_USER1 24
95 #define RTE_LOGTYPE_USER2 25
96 #define RTE_LOGTYPE_USER3 26
97 #define RTE_LOGTYPE_USER4 27
98 #define RTE_LOGTYPE_USER5 28
99 #define RTE_LOGTYPE_USER6 29
100 #define RTE_LOGTYPE_USER7 30
101 #define RTE_LOGTYPE_USER8 31
104 #define RTE_LOGTYPE_FIRST_EXT_ID 32
105 
106 /* Can't use 0, as it gives compiler warnings */
107 #define RTE_LOG_EMERG 1U
108 #define RTE_LOG_ALERT 2U
109 #define RTE_LOG_CRIT 3U
110 #define RTE_LOG_ERR 4U
111 #define RTE_LOG_WARNING 5U
112 #define RTE_LOG_NOTICE 6U
113 #define RTE_LOG_INFO 7U
114 #define RTE_LOG_DEBUG 8U
129 int rte_openlog_stream(FILE *f);
130 
140 void rte_log_set_global_level(uint32_t level);
141 
148 uint32_t rte_log_get_global_level(void);
149 
158 int rte_log_get_level(uint32_t logtype);
159 
170 int rte_log_set_level_regexp(const char *pattern, uint32_t level);
171 
182 int rte_log_set_level(uint32_t logtype, uint32_t level);
183 
196 int rte_log_cur_msg_loglevel(void);
197 
210 int rte_log_cur_msg_logtype(void);
211 
224 int rte_log_register(const char *name);
225 
234 void rte_log_dump(FILE *f);
235 
259 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
260 #ifdef __GNUC__
261 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
262  __attribute__((cold))
263 #endif
264 #endif
265  __attribute__((format(printf, 3, 4)));
266 
293 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
294  __attribute__((format(printf,3,0)));
295 
315 #define RTE_LOG(l, t, ...) \
316  rte_log(RTE_LOG_ ## l, \
317  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
318 
339 #define RTE_LOG_DP(l, t, ...) \
340  (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ? \
341  rte_log(RTE_LOG_ ## l, \
342  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
343  0)
344 
345 #ifdef __cplusplus
346 }
347 #endif
348 
349 #endif /* _RTE_LOG_H_ */
uint32_t level
Definition: rte_log.h:61
int rte_log_set_level_regexp(const char *pattern, uint32_t level)
int rte_log(uint32_t level, uint32_t logtype, const char *format,...)
int rte_log_set_level(uint32_t logtype, uint32_t level)
int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
void rte_log_dump(FILE *f)
uint32_t rte_log_get_global_level(void)
int rte_log_cur_msg_logtype(void)
uint32_t type
Definition: rte_log.h:60
FILE * file
Definition: rte_log.h:62
int rte_log_get_level(uint32_t logtype)
void rte_log_set_global_level(uint32_t level)
int rte_log_register(const char *name)
int rte_log_cur_msg_loglevel(void)