DPDK 25.03.0-rc0
rte_log.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
3 */
4
5#ifndef _RTE_LOG_H_
6#define _RTE_LOG_H_
7
16#include <assert.h>
17#include <stdint.h>
18#include <stdio.h>
19#include <stdarg.h>
20#include <stdbool.h>
21
22#include <rte_common.h>
23#include <rte_config.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/* SDK log type */
30#define RTE_LOGTYPE_EAL 0
31 /* was RTE_LOGTYPE_MALLOC */
32 /* was RTE_LOGTYPE_RING */
33 /* was RTE_LOGTYPE_MEMPOOL */
34 /* was RTE_LOGTYPE_TIMER */
35 /* was RTE_LOGTYPE_PMD */
36 /* was RTE_LOGTYPE_HASH */
37 /* was RTE_LOGTYPE_LPM */
38 /* was RTE_LOGTYPE_KNI */
39 /* was RTE_LOGTYPE_ACL */
40 /* was RTE_LOGTYPE_POWER */
41 /* was RTE_LOGTYPE_METER */
42 /* was RTE_LOGTYPE_SCHED */
43 /* was RTE_LOGTYPE_PORT */
44 /* was RTE_LOGTYPE_TABLE */
45 /* was RTE_LOGTYPE_PIPELINE */
46 /* was RTE_LOGTYPE_MBUF */
47 /* was RTE_LOGTYPE_CRYPTODEV */
48 /* was RTE_LOGTYPE_EFD */
49 /* was RTE_LOGTYPE_EVENTDEV */
50 /* was RTE_LOGTYPE_GSO */
51
52/* these log types can be used in an application */
53#define RTE_LOGTYPE_USER1 24
54#define RTE_LOGTYPE_USER2 25
55#define RTE_LOGTYPE_USER3 26
56#define RTE_LOGTYPE_USER4 27
57#define RTE_LOGTYPE_USER5 28
58#define RTE_LOGTYPE_USER6 29
59#define RTE_LOGTYPE_USER7 30
60#define RTE_LOGTYPE_USER8 31
63#define RTE_LOGTYPE_FIRST_EXT_ID 32
64
65/* Can't use 0, as it gives compiler warnings */
66#define RTE_LOG_EMERG 1U
67#define RTE_LOG_ALERT 2U
68#define RTE_LOG_CRIT 3U
69#define RTE_LOG_ERR 4U
70#define RTE_LOG_WARNING 5U
71#define RTE_LOG_NOTICE 6U
72#define RTE_LOG_INFO 7U
73#define RTE_LOG_DEBUG 8U
74#define RTE_LOG_MAX RTE_LOG_DEBUG
89int rte_openlog_stream(FILE *f);
90
99
109void rte_log_set_global_level(uint32_t level);
110
118
127int rte_log_get_level(uint32_t logtype);
128
139bool rte_log_can_log(uint32_t logtype, uint32_t loglevel);
140
151int rte_log_set_level_pattern(const char *pattern, uint32_t level);
152
163int rte_log_set_level_regexp(const char *regex, uint32_t level);
164
175int rte_log_set_level(uint32_t logtype, uint32_t level);
176
190
204
217int rte_log_register(const char *name);
218
235int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def);
236
245void rte_log_list_types(FILE *out, const char *prefix);
246
255void rte_log_dump(FILE *f);
256
280int rte_log(uint32_t level, uint32_t logtype, const char *format, ...)
283
310int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap)
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#if defined(RTE_TOOLCHAIN_GCC) && !defined(PEDANTIC)
363#define RTE_LOG_CHECK_NO_NEWLINE(fmt) \
364 static_assert(!__builtin_strchr(fmt, '\n'), \
365 "This log format string contains a \\n")
366#else
367#define RTE_LOG_CHECK_NO_NEWLINE(...)
368#endif
369
386#define RTE_LOG_LINE(l, t, ...) do { \
387 RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \
388 RTE_LOG(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
389 RTE_FMT_TAIL(__VA_ARGS__ ,))); \
390} while (0)
391
413#define RTE_LOG_DP_LINE(l, t, ...) do { \
414 RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \
415 RTE_LOG_DP(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
416 RTE_FMT_TAIL(__VA_ARGS__ ,))); \
417} while (0)
418
419#define RTE_LOG_COMMA ,
420
444#define RTE_LOG_LINE_PREFIX(l, t, prefix, args, ...) do { \
445 RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(prefix __VA_ARGS__ ,)); \
446 RTE_LOG(l, t, RTE_FMT(prefix RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
447 args RTE_LOG_COMMA RTE_FMT_TAIL(__VA_ARGS__ ,))); \
448} while (0)
449
473#define RTE_LOG_DP_LINE_PREFIX(l, t, prefix, args, ...) do { \
474 RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(prefix __VA_ARGS__ ,)); \
475 RTE_LOG_DP(l, t, RTE_FMT(prefix RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
476 args RTE_LOG_COMMA RTE_FMT_TAIL(__VA_ARGS__ ,))); \
477} while (0)
478
479#define RTE_LOG_REGISTER_IMPL(type, name, level) \
480int type; \
481RTE_INIT(__##type) \
482{ \
483 type = rte_log_register_type_and_pick_level(name, RTE_LOG_##level); \
484 if (type < 0) \
485 type = RTE_LOGTYPE_EAL; \
486}
487
501#define RTE_LOG_REGISTER(type, name, level) \
502 RTE_LOG_REGISTER_IMPL(type, RTE_STR(name), level)
503
508#define RTE_LOG_REGISTER_DEFAULT(type, level) \
509 RTE_LOG_REGISTER_IMPL(type, RTE_STR(RTE_LOG_DEFAULT_LOGTYPE), level)
510
515#define RTE_LOG_REGISTER_SUFFIX(type, suffix, level) \
516 RTE_LOG_REGISTER_IMPL(type, \
517 RTE_STR(RTE_LOG_DEFAULT_LOGTYPE) "." RTE_STR(suffix), level)
518
519#ifdef __cplusplus
520}
521#endif
522
523#endif /* _RTE_LOG_H_ */
#define __rte_cold
Definition: rte_common.h:432
#define __rte_format_printf(format_index, first_arg)
Definition: rte_common.h:203
int rte_log_set_level_pattern(const char *pattern, uint32_t level)
void rte_log_list_types(FILE *out, const char *prefix)
int rte_log_register_type_and_pick_level(const char *name, uint32_t level_def)
int rte_log_get_level(uint32_t logtype)
void rte_log_set_global_level(uint32_t level)
int rte_log_set_level(uint32_t logtype, uint32_t level)
uint32_t rte_log_get_global_level(void)
int rte_log_cur_msg_loglevel(void)
FILE * rte_log_get_stream(void)
int rte_log_cur_msg_logtype(void)
int rte_log_register(const char *name)
int int rte_vlog(uint32_t level, uint32_t logtype, const char *format, va_list ap) __rte_format_printf(3
void rte_log_dump(FILE *f)
int rte_log_set_level_regexp(const char *regex, uint32_t level)
bool rte_log_can_log(uint32_t logtype, uint32_t loglevel)
int rte_log(uint32_t level, uint32_t logtype, const char *format,...) __rte_cold __rte_format_printf(3
int rte_openlog_stream(FILE *f)