DPDK  17.05.2
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 
55 struct rte_log_dynamic_type;
56 
58 struct rte_logs {
59  uint32_t type;
60  uint32_t level;
61  FILE *file;
62  size_t dynamic_types_len;
63  struct rte_log_dynamic_type *dynamic_types;
64 };
65 
67 extern struct rte_logs rte_logs;
68 
69 /* SDK log type */
70 #define RTE_LOGTYPE_EAL 0
71 #define RTE_LOGTYPE_MALLOC 1
72 #define RTE_LOGTYPE_RING 2
73 #define RTE_LOGTYPE_MEMPOOL 3
74 #define RTE_LOGTYPE_TIMER 4
75 #define RTE_LOGTYPE_PMD 5
76 #define RTE_LOGTYPE_HASH 6
77 #define RTE_LOGTYPE_LPM 7
78 #define RTE_LOGTYPE_KNI 8
79 #define RTE_LOGTYPE_ACL 9
80 #define RTE_LOGTYPE_POWER 10
81 #define RTE_LOGTYPE_METER 11
82 #define RTE_LOGTYPE_SCHED 12
83 #define RTE_LOGTYPE_PORT 13
84 #define RTE_LOGTYPE_TABLE 14
85 #define RTE_LOGTYPE_PIPELINE 15
86 #define RTE_LOGTYPE_MBUF 16
87 #define RTE_LOGTYPE_CRYPTODEV 17
88 #define RTE_LOGTYPE_EFD 18
89 #define RTE_LOGTYPE_EVENTDEV 19
91 /* these log types can be used in an application */
92 #define RTE_LOGTYPE_USER1 24
93 #define RTE_LOGTYPE_USER2 25
94 #define RTE_LOGTYPE_USER3 26
95 #define RTE_LOGTYPE_USER4 27
96 #define RTE_LOGTYPE_USER5 28
97 #define RTE_LOGTYPE_USER6 29
98 #define RTE_LOGTYPE_USER7 30
99 #define RTE_LOGTYPE_USER8 31
102 #define RTE_LOGTYPE_FIRST_EXT_ID 32
103 
104 /* Can't use 0, as it gives compiler warnings */
105 #define RTE_LOG_EMERG 1U
106 #define RTE_LOG_ALERT 2U
107 #define RTE_LOG_CRIT 3U
108 #define RTE_LOG_ERR 4U
109 #define RTE_LOG_WARNING 5U
110 #define RTE_LOG_NOTICE 6U
111 #define RTE_LOG_INFO 7U
112 #define RTE_LOG_DEBUG 8U
127 int rte_openlog_stream(FILE *f);
128 
138 void rte_log_set_global_level(uint32_t level);
139 
143 __rte_deprecated
144 void rte_set_log_level(uint32_t level);
145 
152 uint32_t rte_log_get_global_level(void);
153 
157 __rte_deprecated
158 uint32_t rte_get_log_level(void);
159 
168 __rte_deprecated
169 void rte_set_log_type(uint32_t type, int enable);
170 
174 __rte_deprecated
175 uint32_t rte_get_log_type(void);
176 
187 int rte_log_set_level_regexp(const char *pattern, uint32_t level);
188 
199 int rte_log_set_level(uint32_t logtype, uint32_t level);
200 
213 int rte_log_cur_msg_loglevel(void);
214 
227 int rte_log_cur_msg_logtype(void);
228 
241 int rte_log_register(const char *name);
242 
251 void rte_log_dump(FILE *f);
252 
276 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
277 #ifdef __GNUC__
278 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
279  __attribute__((cold))
280 #endif
281 #endif
282  __attribute__((format(printf, 3, 4)));
283 
310 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
311  __attribute__((format(printf,3,0)));
312 
332 #define RTE_LOG(l, t, ...) \
333  rte_log(RTE_LOG_ ## l, \
334  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
335 
356 #define RTE_LOG_DP(l, t, ...) \
357  (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ? \
358  rte_log(RTE_LOG_ ## l, \
359  RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
360  0)
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 #endif /* _RTE_LOG_H_ */