DPDK  16.11.11
rte_log.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 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 
54 struct rte_logs {
55  uint32_t type;
56  uint32_t level;
57  FILE *file;
58 };
59 
61 extern struct rte_logs rte_logs;
62 
63 /* SDK log type */
64 #define RTE_LOGTYPE_EAL 0x00000001
65 #define RTE_LOGTYPE_MALLOC 0x00000002
66 #define RTE_LOGTYPE_RING 0x00000004
67 #define RTE_LOGTYPE_MEMPOOL 0x00000008
68 #define RTE_LOGTYPE_TIMER 0x00000010
69 #define RTE_LOGTYPE_PMD 0x00000020
70 #define RTE_LOGTYPE_HASH 0x00000040
71 #define RTE_LOGTYPE_LPM 0x00000080
72 #define RTE_LOGTYPE_KNI 0x00000100
73 #define RTE_LOGTYPE_ACL 0x00000200
74 #define RTE_LOGTYPE_POWER 0x00000400
75 #define RTE_LOGTYPE_METER 0x00000800
76 #define RTE_LOGTYPE_SCHED 0x00001000
77 #define RTE_LOGTYPE_PORT 0x00002000
78 #define RTE_LOGTYPE_TABLE 0x00004000
79 #define RTE_LOGTYPE_PIPELINE 0x00008000
80 #define RTE_LOGTYPE_MBUF 0x00010000
81 #define RTE_LOGTYPE_CRYPTODEV 0x00020000
83 /* these log types can be used in an application */
84 #define RTE_LOGTYPE_USER1 0x01000000
85 #define RTE_LOGTYPE_USER2 0x02000000
86 #define RTE_LOGTYPE_USER3 0x04000000
87 #define RTE_LOGTYPE_USER4 0x08000000
88 #define RTE_LOGTYPE_USER5 0x10000000
89 #define RTE_LOGTYPE_USER6 0x20000000
90 #define RTE_LOGTYPE_USER7 0x40000000
91 #define RTE_LOGTYPE_USER8 0x80000000
93 /* Can't use 0, as it gives compiler warnings */
94 #define RTE_LOG_EMERG 1U
95 #define RTE_LOG_ALERT 2U
96 #define RTE_LOG_CRIT 3U
97 #define RTE_LOG_ERR 4U
98 #define RTE_LOG_WARNING 5U
99 #define RTE_LOG_NOTICE 6U
100 #define RTE_LOG_INFO 7U
101 #define RTE_LOG_DEBUG 8U
116 int rte_openlog_stream(FILE *f);
117 
128 void rte_set_log_level(uint32_t level);
129 
133 uint32_t rte_get_log_level(void);
134 
143 void rte_set_log_type(uint32_t type, int enable);
144 
148 uint32_t rte_get_log_type(void);
149 
162 int rte_log_cur_msg_loglevel(void);
163 
176 int rte_log_cur_msg_logtype(void);
177 
202 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
203 #ifdef __GNUC__
204 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
205  __attribute__((cold))
206 #endif
207 #endif
208  __attribute__((format(printf, 3, 4)));
209 
236 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
237  __attribute__((format(printf,3,0)));
238 
265 #define RTE_LOG(l, t, ...) \
266  (void)((RTE_LOG_ ## l <= RTE_LOG_LEVEL) ? \
267  rte_log(RTE_LOG_ ## l, \
268  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
269  0)
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 
275 #endif /* _RTE_LOG_H_ */
uint32_t level
Definition: rte_log.h:56
int rte_log(uint32_t level, uint32_t logtype, const char *format,...)
int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
uint32_t rte_get_log_type(void)
int rte_log_cur_msg_logtype(void)
void rte_set_log_level(uint32_t level)
uint32_t type
Definition: rte_log.h:55
void rte_set_log_type(uint32_t type, int enable)
FILE * file
Definition: rte_log.h:57
uint32_t rte_get_log_level(void)
int rte_log_cur_msg_loglevel(void)