4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
42 * This file provides a log API to RTE applications.
53 /** The rte_log structure. */
55 uint32_t type; /**< Bitfield with enabled logs. */
56 uint32_t level; /**< Log level. */
57 FILE *file; /**< Output file set by rte_openlog_stream, or NULL. */
60 /** Global log informations */
61 extern struct rte_logs rte_logs;
64 #define RTE_LOGTYPE_EAL 0x00000001 /**< Log related to eal. */
65 #define RTE_LOGTYPE_MALLOC 0x00000002 /**< Log related to malloc. */
66 #define RTE_LOGTYPE_RING 0x00000004 /**< Log related to ring. */
67 #define RTE_LOGTYPE_MEMPOOL 0x00000008 /**< Log related to mempool. */
68 #define RTE_LOGTYPE_TIMER 0x00000010 /**< Log related to timers. */
69 #define RTE_LOGTYPE_PMD 0x00000020 /**< Log related to poll mode driver. */
70 #define RTE_LOGTYPE_HASH 0x00000040 /**< Log related to hash table. */
71 #define RTE_LOGTYPE_LPM 0x00000080 /**< Log related to LPM. */
72 #define RTE_LOGTYPE_KNI 0x00000100 /**< Log related to KNI. */
73 #define RTE_LOGTYPE_ACL 0x00000200 /**< Log related to ACL. */
74 #define RTE_LOGTYPE_POWER 0x00000400 /**< Log related to power. */
75 #define RTE_LOGTYPE_METER 0x00000800 /**< Log related to QoS meter. */
76 #define RTE_LOGTYPE_SCHED 0x00001000 /**< Log related to QoS port scheduler. */
77 #define RTE_LOGTYPE_PORT 0x00002000 /**< Log related to port. */
78 #define RTE_LOGTYPE_TABLE 0x00004000 /**< Log related to table. */
79 #define RTE_LOGTYPE_PIPELINE 0x00008000 /**< Log related to pipeline. */
80 #define RTE_LOGTYPE_MBUF 0x00010000 /**< Log related to mbuf. */
81 #define RTE_LOGTYPE_CRYPTODEV 0x00020000 /**< Log related to cryptodev. */
82 #define RTE_LOGTYPE_EFD 0x00040000 /**< Log related to EFD. */
83 #define RTE_LOGTYPE_EVENTDEV 0x00080000 /**< Log related to eventdev. */
85 /* these log types can be used in an application */
86 #define RTE_LOGTYPE_USER1 0x01000000 /**< User-defined log type 1. */
87 #define RTE_LOGTYPE_USER2 0x02000000 /**< User-defined log type 2. */
88 #define RTE_LOGTYPE_USER3 0x04000000 /**< User-defined log type 3. */
89 #define RTE_LOGTYPE_USER4 0x08000000 /**< User-defined log type 4. */
90 #define RTE_LOGTYPE_USER5 0x10000000 /**< User-defined log type 5. */
91 #define RTE_LOGTYPE_USER6 0x20000000 /**< User-defined log type 6. */
92 #define RTE_LOGTYPE_USER7 0x40000000 /**< User-defined log type 7. */
93 #define RTE_LOGTYPE_USER8 0x80000000 /**< User-defined log type 8. */
95 /* Can't use 0, as it gives compiler warnings */
96 #define RTE_LOG_EMERG 1U /**< System is unusable. */
97 #define RTE_LOG_ALERT 2U /**< Action must be taken immediately. */
98 #define RTE_LOG_CRIT 3U /**< Critical conditions. */
99 #define RTE_LOG_ERR 4U /**< Error conditions. */
100 #define RTE_LOG_WARNING 5U /**< Warning conditions. */
101 #define RTE_LOG_NOTICE 6U /**< Normal but significant condition. */
102 #define RTE_LOG_INFO 7U /**< Informational. */
103 #define RTE_LOG_DEBUG 8U /**< Debug-level messages. */
106 * Change the stream that will be used by the logging system.
108 * This can be done at any time. The f argument represents the stream
109 * to be used to send the logs. If f is NULL, the default output is
113 * Pointer to the stream.
116 * - Negative on error.
118 int rte_openlog_stream(FILE *f);
121 * Set the global log level.
123 * After this call, logs with a level lower or equal than the level
124 * passed as argument will be displayed.
127 * Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
129 void rte_set_log_level(uint32_t level);
132 * Get the global log level.
134 uint32_t rte_get_log_level(void);
137 * Enable or disable the log type.
140 * Log type, for example, RTE_LOGTYPE_EAL.
142 * True for enable; false for disable.
144 void rte_set_log_type(uint32_t type, int enable);
147 * Get the global log type.
149 uint32_t rte_get_log_type(void);
152 * Get the current loglevel for the message being processed.
154 * Before calling the user-defined stream for logging, the log
155 * subsystem sets a per-lcore variable containing the loglevel and the
156 * logtype of the message being processed. This information can be
157 * accessed by the user-defined log output function through this
161 * The loglevel of the message being processed.
163 int rte_log_cur_msg_loglevel(void);
166 * Get the current logtype for the message being processed.
168 * Before calling the user-defined stream for logging, the log
169 * subsystem sets a per-lcore variable containing the loglevel and the
170 * logtype of the message being processed. This information can be
171 * accessed by the user-defined log output function through this
175 * The logtype of the message being processed.
177 int rte_log_cur_msg_logtype(void);
180 * Generates a log message.
182 * The message will be sent in the stream defined by the previous call
183 * to rte_openlog_stream().
185 * The level argument determines if the log should be displayed or
186 * not, depending on the global rte_logs variable.
188 * The preferred alternative is the RTE_LOG() because it adds the
189 * level and type in the logged string.
192 * Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
194 * The log type, for example, RTE_LOGTYPE_EAL.
196 * The format string, as in printf(3), followed by the variable arguments
197 * required by the format.
200 * - Negative on error.
202 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
204 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
205 __attribute__((cold))
208 __attribute__((format(printf, 3, 4)));
211 * Generates a log message.
213 * The message will be sent in the stream defined by the previous call
214 * to rte_openlog_stream().
216 * The level argument determines if the log should be displayed or
217 * not, depending on the global rte_logs variable. A trailing
218 * newline may be added if needed.
220 * The preferred alternative is the RTE_LOG() because it adds the
221 * level and type in the logged string.
224 * Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
226 * The log type, for example, RTE_LOGTYPE_EAL.
228 * The format string, as in printf(3), followed by the variable arguments
229 * required by the format.
231 * The va_list of the variable arguments required by the format.
234 * - Negative on error.
236 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
237 __attribute__((format(printf,3,0)));
240 * Generates a log message.
242 * The RTE_LOG() is a helper that prefixes the string with the log level
243 * and type, and call rte_log().
246 * Log level. A value between EMERG (1) and DEBUG (8). The short name is
247 * expanded by the macro, so it cannot be an integer value.
249 * The log type, for example, EAL. The short name is expanded by the
250 * macro, so it cannot be an integer value.
252 * The fmt string, as in printf(3), followed by the variable arguments
253 * required by the format.
256 * - Negative on error.
258 #define RTE_LOG(l, t, ...) \
259 rte_log(RTE_LOG_ ## l, \
260 RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)
263 * Generates a log message for data path.
265 * Similar to RTE_LOG(), except that it is removed at compilation time
266 * if the RTE_LOG_DP_LEVEL configuration option is lower than the log
270 * Log level. A value between EMERG (1) and DEBUG (8). The short name is
271 * expanded by the macro, so it cannot be an integer value.
273 * The log type, for example, EAL. The short name is expanded by the
274 * macro, so it cannot be an integer value.
276 * The fmt string, as in printf(3), followed by the variable arguments
277 * required by the format.
280 * - Negative on error.
282 #define RTE_LOG_DP(l, t, ...) \
283 (void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ? \
284 rte_log(RTE_LOG_ ## l, \
285 RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
292 #endif /* _RTE_LOG_H_ */