DPDK  16.07.2
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 #include "rte_common.h" /* for __rte_deprecated macro */
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #include <stdint.h>
52 #include <stdio.h>
53 #include <stdarg.h>
54 
56 struct rte_logs {
57  uint32_t type;
58  uint32_t level;
59  FILE *file;
60 };
61 
63 extern struct rte_logs rte_logs;
64 
65 /* SDK log type */
66 #define RTE_LOGTYPE_EAL 0x00000001
67 #define RTE_LOGTYPE_MALLOC 0x00000002
68 #define RTE_LOGTYPE_RING 0x00000004
69 #define RTE_LOGTYPE_MEMPOOL 0x00000008
70 #define RTE_LOGTYPE_TIMER 0x00000010
71 #define RTE_LOGTYPE_PMD 0x00000020
72 #define RTE_LOGTYPE_HASH 0x00000040
73 #define RTE_LOGTYPE_LPM 0x00000080
74 #define RTE_LOGTYPE_KNI 0x00000100
75 #define RTE_LOGTYPE_ACL 0x00000200
76 #define RTE_LOGTYPE_POWER 0x00000400
77 #define RTE_LOGTYPE_METER 0x00000800
78 #define RTE_LOGTYPE_SCHED 0x00001000
79 #define RTE_LOGTYPE_PORT 0x00002000
80 #define RTE_LOGTYPE_TABLE 0x00004000
81 #define RTE_LOGTYPE_PIPELINE 0x00008000
82 #define RTE_LOGTYPE_MBUF 0x00010000
83 #define RTE_LOGTYPE_CRYPTODEV 0x00020000
85 /* these log types can be used in an application */
86 #define RTE_LOGTYPE_USER1 0x01000000
87 #define RTE_LOGTYPE_USER2 0x02000000
88 #define RTE_LOGTYPE_USER3 0x04000000
89 #define RTE_LOGTYPE_USER4 0x08000000
90 #define RTE_LOGTYPE_USER5 0x10000000
91 #define RTE_LOGTYPE_USER6 0x20000000
92 #define RTE_LOGTYPE_USER7 0x40000000
93 #define RTE_LOGTYPE_USER8 0x80000000
95 /* Can't use 0, as it gives compiler warnings */
96 #define RTE_LOG_EMERG 1U
97 #define RTE_LOG_ALERT 2U
98 #define RTE_LOG_CRIT 3U
99 #define RTE_LOG_ERR 4U
100 #define RTE_LOG_WARNING 5U
101 #define RTE_LOG_NOTICE 6U
102 #define RTE_LOG_INFO 7U
103 #define RTE_LOG_DEBUG 8U
106 extern FILE *eal_default_log_stream;
107 
121 int rte_openlog_stream(FILE *f);
122 
133 void rte_set_log_level(uint32_t level);
134 
138 uint32_t rte_get_log_level(void);
139 
148 void rte_set_log_type(uint32_t type, int enable);
149 
153 uint32_t rte_get_log_type(void);
154 
167 int rte_log_cur_msg_loglevel(void);
168 
181 int rte_log_cur_msg_logtype(void);
182 
190 __rte_deprecated
191 void rte_log_set_history(int enable);
192 
200 __rte_deprecated
201 void rte_log_dump_history(FILE *f);
202 
219 __rte_deprecated
220 int rte_log_add_in_history(const char *buf, size_t size);
221 
246 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
247 #ifdef __GNUC__
248 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
249  __attribute__((cold))
250 #endif
251 #endif
252  __attribute__((format(printf, 3, 4)));
253 
280 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
281  __attribute__((format(printf,3,0)));
282 
309 #define RTE_LOG(l, t, ...) \
310  (void)((RTE_LOG_ ## l <= RTE_LOG_LEVEL) ? \
311  rte_log(RTE_LOG_ ## l, \
312  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
313  0)
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 
319 #endif /* _RTE_LOG_H_ */