4 * Copyright(c) 2010-2013 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.
43 * This file provides a log API to RTE applications.
54 /** The rte_log structure. */
56 uint32_t type; /**< Bitfield with enabled logs. */
57 uint32_t level; /**< Log level. */
58 FILE *file; /**< Pointer to current FILE* for logs. */
61 /** Global log informations */
62 extern struct rte_logs rte_logs;
65 #define RTE_LOGTYPE_EAL 0x00000001 /**< Log related to eal. */
66 #define RTE_LOGTYPE_MALLOC 0x00000002 /**< Log related to malloc. */
67 #define RTE_LOGTYPE_RING 0x00000004 /**< Log related to ring. */
68 #define RTE_LOGTYPE_MEMPOOL 0x00000008 /**< Log related to mempool. */
69 #define RTE_LOGTYPE_TIMER 0x00000010 /**< Log related to timers. */
70 #define RTE_LOGTYPE_PMD 0x00000020 /**< Log related to poll mode driver. */
71 #define RTE_LOGTYPE_HASH 0x00000040 /**< Log related to hash table. */
72 #define RTE_LOGTYPE_LPM 0x00000080 /**< Log related to LPM. */
73 #define RTE_LOGTYPE_KNI 0x00000100 /**< Log related to KNI. */
74 #define RTE_LOGTYPE_PMAC 0x00000200 /**< Log related to PMAC. */
75 #define RTE_LOGTYPE_POWER 0x00000400 /**< Log related to power. */
76 #define RTE_LOGTYPE_METER 0x00000800 /**< Log related to QoS meter. */
77 #define RTE_LOGTYPE_SCHED 0x00001000 /**< Log related to QoS port scheduler. */
79 /* these log types can be used in an application */
80 #define RTE_LOGTYPE_USER1 0x01000000 /**< User-defined log type 1. */
81 #define RTE_LOGTYPE_USER2 0x02000000 /**< User-defined log type 2. */
82 #define RTE_LOGTYPE_USER3 0x04000000 /**< User-defined log type 3. */
83 #define RTE_LOGTYPE_USER4 0x08000000 /**< User-defined log type 4. */
84 #define RTE_LOGTYPE_USER5 0x10000000 /**< User-defined log type 5. */
85 #define RTE_LOGTYPE_USER6 0x20000000 /**< User-defined log type 6. */
86 #define RTE_LOGTYPE_USER7 0x40000000 /**< User-defined log type 7. */
87 #define RTE_LOGTYPE_USER8 0x80000000 /**< User-defined log type 8. */
89 /* Can't use 0, as it gives compiler warnings */
90 #define RTE_LOG_EMERG 1U /**< System is unusable. */
91 #define RTE_LOG_ALERT 2U /**< Action must be taken immediately. */
92 #define RTE_LOG_CRIT 3U /**< Critical conditions. */
93 #define RTE_LOG_ERR 4U /**< Error conditions. */
94 #define RTE_LOG_WARNING 5U /**< Warning conditions. */
95 #define RTE_LOG_NOTICE 6U /**< Normal but significant condition. */
96 #define RTE_LOG_INFO 7U /**< Informational. */
97 #define RTE_LOG_DEBUG 8U /**< Debug-level messages. */
99 /** The default log stream. */
100 extern FILE *eal_default_log_stream;
103 * Change the stream that will be used by the logging system.
105 * This can be done at any time. The f argument represents the stream
106 * to be used to send the logs. If f is NULL, the default output is
107 * used, which is the serial line in case of bare metal, or directly
108 * sent to syslog in case of linux application.
111 * Pointer to the stream.
114 * - Negative on error.
116 int rte_openlog_stream(FILE *f);
119 * Set the global log level.
121 * After this call, all logs that are lower or equal than level and
122 * lower or equal than the RTE_LOG_LEVEL configuration option will be
126 * Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
128 void rte_set_log_level(uint32_t level);
131 * Enable or disable the log type.
134 * Log type, for example, RTE_LOGTYPE_EAL.
136 * True for enable; false for disable.
138 void rte_set_log_type(uint32_t type, int enable);
141 * Get the current loglevel for the message being processed.
143 * Before calling the user-defined stream for logging, the log
144 * subsystem sets a per-lcore variable containing the loglevel and the
145 * logtype of the message being processed. This information can be
146 * accessed by the user-defined log output function through this
150 * The loglevel of the message being processed.
152 int rte_log_cur_msg_loglevel(void);
155 * Get the current logtype for the message being processed.
157 * Before calling the user-defined stream for logging, the log
158 * subsystem sets a per-lcore variable containing the loglevel and the
159 * logtype of the message being processed. This information can be
160 * accessed by the user-defined log output function through this
164 * The logtype of the message being processed.
166 int rte_log_cur_msg_logtype(void);
169 * Enable or disable the history (enabled by default)
172 * true to enable, or 0 to disable history.
174 void rte_log_set_history(int enable);
177 * Dump the log history to the console.
179 void rte_log_dump_history(void);
182 * Add a log message to the history.
184 * This function can be called from a user-defined log stream. It adds
185 * the given message in the history that can be dumped using
186 * rte_log_dump_history().
189 * A data buffer containing the message to be saved in the history.
191 * The length of the data buffer.
194 * - (-ENOBUFS) if there is no room to store the message.
196 int rte_log_add_in_history(const char *buf, size_t size);
199 * Generates a log message.
201 * The message will be sent in the stream defined by the previous call
202 * to rte_openlog_stream().
204 * The level argument determines if the log should be displayed or
205 * not, depending on the global rte_logs variable.
207 * The preferred alternative is the RTE_LOG() function because debug logs may
208 * be removed at compilation time if optimization is enabled. Moreover,
209 * logs are automatically prefixed by type when using the macro.
212 * Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
214 * The log type, for example, RTE_LOGTYPE_EAL.
216 * The format string, as in printf(3), followed by the variable arguments
217 * required by the format.
220 * - Negative on error.
222 int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
223 __attribute__((cold))
224 __attribute__((format(printf, 3, 4)));
227 * Generates a log message.
229 * The message will be sent in the stream defined by the previous call
230 * to rte_openlog_stream().
232 * The level argument determines if the log should be displayed or
233 * not, depending on the global rte_logs variable. A trailing
234 * newline may be added if needed.
236 * The preferred alternative is the RTE_LOG() because debug logs may be
237 * removed at compilation time.
240 * Log level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
242 * The log type, for example, RTE_LOGTYPE_EAL.
244 * The format string, as in printf(3), followed by the variable arguments
245 * required by the format.
247 * The va_list of the variable arguments required by the format.
250 * - Negative on error.
252 int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap);
255 * Generates a log message.
257 * The RTE_LOG() is equivalent to rte_log() with two differences:
259 * - RTE_LOG() can be used to remove debug logs at compilation time,
260 * depending on RTE_LOG_LEVEL configuration option, and compilation
261 * optimization level. If optimization is enabled, the tests
262 * involving constants only are pre-computed. If compilation is done
263 * with -O0, these tests will be done at run time.
264 * - The log level and log type names are smaller, for example:
265 * RTE_LOG(INFO, EAL, "this is a %s", "log");
268 * Log level. A value between EMERG (1) and DEBUG (8). The short name is
269 * expanded by the macro, so it cannot be an integer value.
271 * The log type, for example, EAL. The short name is expanded by the
272 * macro, so it cannot be an integer value.
274 * The fmt string, as in printf(3), followed by the variable arguments
275 * required by the format.
277 * The variable list of arguments according to the format string.
280 * - Negative on error.
282 #define RTE_LOG(l, t, ...) \
283 (void)(((RTE_LOG_ ## l <= RTE_LOG_LEVEL) && \
284 (RTE_LOG_ ## l <= rte_logs.level) && \
285 (RTE_LOGTYPE_ ## t & rte_logs.type)) ? \
286 rte_log(RTE_LOG_ ## l, \
287 RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
294 #endif /* _RTE_LOG_H_ */