DPDK  17.02.1
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 
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
82 #define RTE_LOGTYPE_EFD 0x00040000
84 /* these log types can be used in an application */
85 #define RTE_LOGTYPE_USER1 0x01000000
86 #define RTE_LOGTYPE_USER2 0x02000000
87 #define RTE_LOGTYPE_USER3 0x04000000
88 #define RTE_LOGTYPE_USER4 0x08000000
89 #define RTE_LOGTYPE_USER5 0x10000000
90 #define RTE_LOGTYPE_USER6 0x20000000
91 #define RTE_LOGTYPE_USER7 0x40000000
92 #define RTE_LOGTYPE_USER8 0x80000000
94 /* Can't use 0, as it gives compiler warnings */
95 #define RTE_LOG_EMERG 1U
96 #define RTE_LOG_ALERT 2U
97 #define RTE_LOG_CRIT 3U
98 #define RTE_LOG_ERR 4U
99 #define RTE_LOG_WARNING 5U
100 #define RTE_LOG_NOTICE 6U
101 #define RTE_LOG_INFO 7U
102 #define RTE_LOG_DEBUG 8U
117 int rte_openlog_stream(FILE *f);
118 
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 
201 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
202 #ifdef __GNUC__
203 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
204  __attribute__((cold))
205 #endif
206 #endif
207  __attribute__((format(printf, 3, 4)));
208 
235 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
236  __attribute__((format(printf,3,0)));
237 
257 #define RTE_LOG(l, t, ...) \
258  rte_log(RTE_LOG_ ## l, \
259  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
260 
281 #define RTE_LOG_DP(l, t, ...) \
282  (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ? \
283  rte_log(RTE_LOG_ ## l, \
284  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
285  0)
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif /* _RTE_LOG_H_ */