rte_log.h(3)

πŸ’– NAME πŸ’–

rte_log.h β€” bestie, this is the logging header. You're reading page rte_log.h(3), straight out of the Library Functions Manual (section 3, the C library functions section, and yes she's iconic). ✨


🌸 SYNOPSIS 🌸

Okay so before literally anything else, you gotta pull in the whole girl squad of headers:

#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#include <rte_common.h>
#include <rte_config.h>

πŸŽ€ Macros πŸŽ€

These are the log type IDs and the log levels, and you will respect them:

  • #define RTE_LOGTYPE_EAL 0 β€” the EAL log type, sitting at 0. she's the OG.
  • #define RTE_LOGTYPE_USER1 24
  • #define RTE_LOGTYPE_USER2 25
  • #define RTE_LOGTYPE_USER3 26
  • #define RTE_LOGTYPE_USER4 27
  • #define RTE_LOGTYPE_USER5 28
  • #define RTE_LOGTYPE_USER6 29
  • #define RTE_LOGTYPE_USER7 30
  • #define RTE_LOGTYPE_USER8 31 β€” the user log types 1 through 8, numbered 24 all the way up to 31. one through eight, no skipping πŸ’…
  • #define RTE_LOGTYPE_FIRST_EXT_ID 32 β€” this one lives at 32.
  • #define RTE_LOG_EMERG 1U β€” emergency. the loudest one.
  • #define RTE_LOG_ALERT 2U β€” alert.
  • #define RTE_LOG_CRIT 3U β€” critical.
  • #define RTE_LOG_ERR 4U β€” error.
  • #define RTE_LOG_WARNING 5U β€” warning.
  • #define RTE_LOG_NOTICE 6U β€” notice.
  • #define RTE_LOG_INFO 7U β€” info.
  • #define RTE_LOG_DEBUG 8U β€” debug, the chattiest.
  • #define RTE_LOG_MAX RTE_LOG_DEBUG β€” the max is literally just RTE_LOG_DEBUG. as she should be. periodt.
  • #define RTE_LOG(l, t, ...) β€” macro, takes l, t, then whatever else.
  • #define RTE_LOG_DP(l, t, ...) β€” same shape: l, t, ....
  • #define RTE_LOG_LINE(l, t, ...) β€” l, t, ....
  • #define RTE_LOG_DP_LINE(l, t, ...) β€” l, t, ....
  • #define RTE_LOG_LINE_PREFIX(l, t, prefix, args, ...) β€” now with a prefix and an args in the middle, bestie.
  • #define RTE_LOG_DP_LINE_PREFIX(l, t, prefix, args, ...) β€” same energy, l, t, prefix, args, ....
  • #define RTE_LOG_REGISTER(type, name, level) β€” registration macro, args: type, name, level.
  • #define RTE_LOG_REGISTER_DEFAULT(type, level) β€” args: type, level.
  • #define RTE_LOG_REGISTER_SUFFIX(type, suffix, level) β€” args: type, suffix, level.

πŸ¦‹ Functions πŸ¦‹

The whole function roster, no gatekeeping:

  • int rte_openlog_stream (FILE *f)
  • FILE * rte_log_get_stream (void)
  • void rte_log_set_global_level (uint32_t level)
  • uint32_t rte_log_get_global_level (void)
  • int rte_log_get_level (uint32_t logtype)
  • bool rte_log_can_log (uint32_t logtype, uint32_t loglevel)
  • int rte_log_set_level_pattern (const char *pattern, uint32_t level)
  • int rte_log_set_level_regexp (const char *regex, uint32_t level)
  • int rte_log_set_level (uint32_t logtype, uint32_t level)
  • int rte_log_cur_msg_loglevel (void)
  • int rte_log_cur_msg_logtype (void)
  • int rte_log_register (const char *name)
  • int rte_log_register_type_and_pick_level (const char *name, uint32_t level_def)
  • void rte_log_list_types (FILE *out, const char *prefix)
  • void rte_log_dump (FILE *f)

and then these two, which I am typing exactly as the page gives them, because bestie, look at them, and also I do not fix canon:

int rte_log (uint32_t level, uint32_t logtype, const char *format,...) __rte_cold __rte_format_printf(3
int int rte_vlog (uint32_t level, uint32_t logtype, const char *format, va_list ap) __rte_format_printf(3
🫢 Not me being obsessed with the fact that it says int int and the (3 never closes. That's just how she's written down. Don't come for me, I copied it right.

πŸ‘‘ Detailed Description πŸ‘‘

RTE Logs API πŸ’–

This file provides a log API to RTE applications.

Definition in file rte_log.h.

✨ Macro Definition Documentation ✨

Okay bestie, this is where the actual macro lore lives. Every single one, no skips. 🫢


#define RTE_LOGTYPE_EAL 0

Log related to eal.

Definition at line 30 of file rte_log.h.

#define RTE_LOGTYPE_USER1 24

User-defined log type 1.

Definition at line 53 of file rte_log.h.

#define RTE_LOGTYPE_USER2 25

User-defined log type 2.

Definition at line 54 of file rte_log.h.

#define RTE_LOGTYPE_USER3 26

User-defined log type 3.

Definition at line 55 of file rte_log.h.

#define RTE_LOGTYPE_USER4 27

User-defined log type 4.

Definition at line 56 of file rte_log.h.

#define RTE_LOGTYPE_USER5 28

User-defined log type 5.

Definition at line 57 of file rte_log.h.

#define RTE_LOGTYPE_USER6 29

User-defined log type 6.

Definition at line 58 of file rte_log.h.

#define RTE_LOGTYPE_USER7 30

User-defined log type 7.

Definition at line 59 of file rte_log.h.

#define RTE_LOGTYPE_USER8 31

User-defined log type 8.

Definition at line 60 of file rte_log.h.

#define RTE_LOGTYPE_FIRST_EXT_ID 32

First identifier for extended logs

Definition at line 63 of file rte_log.h.


🌈 The log levels, from "we are SO cooked" to "just chatting" πŸ’€

These are the severity vibes. Lower number = more dire. <hotpink>1U</hotpink> is the end of the world, <mint>8U</mint> is you whispering into the void. 🌸

#define RTE_LOG_EMERG 1U

System is unusable.

Definition at line 66 of file rte_log.h.

#define RTE_LOG_ALERT 2U

Action must be taken immediately.

Definition at line 67 of file rte_log.h.

#define RTE_LOG_CRIT 3U

Critical conditions.

Definition at line 68 of file rte_log.h.

#define RTE_LOG_ERR 4U

Error conditions.

Definition at line 69 of file rte_log.h.

#define RTE_LOG_WARNING 5U

Warning conditions.

Definition at line 70 of file rte_log.h.

#define RTE_LOG_NOTICE 6U

Normal but significant condition.

Definition at line 71 of file rte_log.h.

#define RTE_LOG_INFO 7U

Informational.

Definition at line 72 of file rte_log.h.

#define RTE_LOG_DEBUG 8U

Debug-level messages.

Definition at line 73 of file rte_log.h.

#define RTE_LOG_MAX RTE_LOG_DEBUG

Most detailed log level.

Definition at line 74 of file rte_log.h.


πŸŽ€ The logging macros themselves (the main characters, honestly) πŸ‘‘

#define RTE_LOG( l, t, ...)

Value:

rte_log(RTE_LOG_ ## l,                 \
    RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__)

Generates a log message.

The RTE_LOG() is a helper that prefixes the string with the log level and type, and call rte_log().

Parameters

  • l β€” Log level. A value between EMERG (1) and DEBUG (8). The short name is expanded by the macro, so it cannot be an integer value. (like, she needs the name, not a number, ok?)
  • t β€” The log type, for example, EAL. The short name is expanded by the macro, so it cannot be an integer value.
  • ... β€” The fmt string, as in printf(3), followed by the variable arguments required by the format.

Returns

  • <mint>0</mint>: Success. πŸ’–
  • Negative on error. 😭

Definition at line 332 of file rte_log.h.

#define RTE_LOG_DP( l, t, ...)

Value:

(void)((RTE_LOG_ ## l <= RTE_LOG_DP_LEVEL) ?        \
 rte_log(RTE_LOG_ ## l,                 \
     RTE_LOGTYPE_ ## t, # t ": " __VA_ARGS__) : \
 0)

Generates a log message for data path.

Similar to RTE_LOG(), except that it is removed at compilation time if the RTE_LOG_DP_LEVEL configuration option is lower than the log level argument. (yes bestie, it literally vanishes. poof. gone. the compiler said "not today") ✨

Parameters

  • l β€” Log level. A value between EMERG (1) and DEBUG (8). The short name is expanded by the macro, so it cannot be an integer value.
  • t β€” The log type, for example, EAL. The short name is expanded by the macro, so it cannot be an integer value.
  • ... β€” The fmt string, as in printf(3), followed by the variable arguments required by the format.

Returns

  • <mint>0</mint>: Success.
  • Negative on error.

Definition at line 356 of file rte_log.h.

#define RTE_LOG_LINE( l, t, ...)

Value:

do { \
    RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \
    RTE_LOG(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
        RTE_FMT_TAIL(__VA_ARGS__ ,))); \
} while (0)

Generates a log message with a single trailing newline.

The RTE_LOG_LINE() is a helper that expands logging of a message with RTE_LOG() appending a single newline to the formatted message. ONE newline. not two. she's on her newline regulation arc. πŸ’…

Parameters

  • l β€” Log level. A value between EMERG (1) and DEBUG (8). The short name is expanded by the macro, so it cannot be an integer value.
  • t β€” The log type, for example, EAL. The short name is expanded by the macro, so it cannot be an integer value.
  • ... β€” The fmt string, as in printf(3), followed by the variable arguments required by the format.

Definition at line 386 of file rte_log.h.

#define RTE_LOG_DP_LINE( l, t, ...)

Value:

do { \
    RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(__VA_ARGS__ ,)); \
    RTE_LOG_DP(l, t, RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
        RTE_FMT_TAIL(__VA_ARGS__ ,))); \
} while (0)

Generates a log message for data path with a single trailing newline.

Similar to RTE_LOG_LINE(), except that it is removed at compilation time if the RTE_LOG_DP_LEVEL configuration option is lower than the log level argument.

The RTE_LOG_LINE() is a helper that expands logging of a message with RTE_LOG_DP() appending a single newline to the formatted message.

Parameters

  • l β€” Log level. A value between EMERG (1) and DEBUG (8). The short name is expanded by the macro, so it cannot be an integer value.
  • t β€” The log type, for example, EAL. The short name is expanded by the macro, so it cannot be an integer value.
  • ... β€” The fmt string, as in printf(3), followed by the variable arguments required by the format.

Definition at line 413 of file rte_log.h.

#define RTE_LOG_LINE_PREFIX( l, t, prefix, args, ...)

Value:

do { \
    RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(prefix __VA_ARGS__ ,)); \
    RTE_LOG(l, t, RTE_FMT(prefix RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
        args RTE_LOG_COMMA RTE_FMT_TAIL(__VA_ARGS__ ,))); \
} while (0)

Generates a log message with a supplied prefix and arguments with a single trailing newline.

The RTE_LOG_LINE_PREFIX() is a helper that expands logging of a message with RTE_LOG() prepending the supplied prefix and arguments appending a single newline to the formatted message. (prefix goes in FRONT bestie, we love a front-row seat) ✨

Parameters

  • l β€” Log level. A value between EMERG (1) and DEBUG (8). The short name is expanded by the macro, so it cannot be an integer value.
  • t β€” The log type, for example, EAL. The short name is expanded by the macro, so it cannot be an integer value.
  • prefix β€” The prefix format string.
  • args β€” The arguments for the prefix format string. If args contains multiple arguments use RTE_LOG_COMMA to defer expansion. (iykyk β€” it's a macro-expansion timing thing)
  • ... β€” The fmt string, as in printf(3), followed by the variable arguments required by the format.

Definition at line 444 of file rte_log.h.

#define RTE_LOG_DP_LINE_PREFIX( l, t, prefix, args, ...)

Value:

do { \
    RTE_LOG_CHECK_NO_NEWLINE(RTE_FMT_HEAD(prefix __VA_ARGS__ ,)); \
    RTE_LOG_DP(l, t, RTE_FMT(prefix RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
        args RTE_LOG_COMMA RTE_FMT_TAIL(__VA_ARGS__ ,))); \
} while (0)

Generates a log message for the data path with a supplied prefix and arguments with a single trailing newline.

The RTE_LOG_DP_LINE_PREFIX() is a helper that expands logging of a message with RTE_LOG_DP() prepending the supplied prefix and arguments appending a single newline to the formatted message.

Parameters

  • l β€” Log level. A value between EMERG (1) and DEBUG (8). The short name is expanded by the macro, so it cannot be an integer value.
  • t β€” The log type, for example, EAL. The short name is expanded by the macro, so it cannot be an integer value.
  • prefix β€” The prefix format string.
  • args β€” The arguments for the prefix format string. If args contains multiple arguments use RTE_LOG_COMMA to defer expansion.
  • ... β€” The fmt string, as in printf(3), followed by the variable arguments required by the format.

Definition at line 473 of file rte_log.h.


🌸 Registering your own logtypes (glow-up era) πŸ¦‹

#define RTE_LOG_REGISTER( type, name, level)

Value:

RTE_LOG_REGISTER_IMPL(type, RTE_STR(name), level)

Register a dynamic log type in constructor context with its name and level.

It is a wrapper macro for declaring the logtype, register the log and sets it's level in the constructor context. (one macro, three jobs, she's booked and busy) πŸ’…

Parameters

  • type β€” The log type identifier
  • name β€” Name for the log type to be registered
  • level β€” Log level. A value between EMERG (1) and DEBUG (8).

Definition at line 501 of file rte_log.h.

#define RTE_LOG_REGISTER_DEFAULT( type, level)

Value:

RTE_LOG_REGISTER_IMPL(type, RTE_STR(RTE_LOG_DEFAULT_LOGTYPE), level)

This is an equivalent to RTE_LOG_REGISTER, but relying on the build system to select the right format for the logtype. (letting the build system pick the fit? iconic delegation honestly)

Definition at line 508 of file rte_log.h.

#define RTE_LOG_REGISTER_SUFFIX( type, suffix, level)

Value:

RTE_LOG_REGISTER_IMPL(type,                       \
     RTE_STR(RTE_LOG_DEFAULT_LOGTYPE) "." RTE_STR(suffix), level)

This is an equivalent to RTE_LOG_REGISTER, but relying on the build system to select the right prefix for the logtype.

Definition at line 515 of file rte_log.h.

πŸ’… FUNCTION DOCUMENTATION πŸ’…

okay bestie, this is the part with all the actual functions β€” the little buttons you press to make logging do stuff. each one gets its own mini moment. let's go πŸ¦‹


int rte_openlog_stream (FILE * f)

Swap out the stream the logging system writes to. πŸ’–

you can do this whenever, literally any time, no bad vibes. that f argument is the stream where the logs go. and if f is NULL? bestie, it just falls back to the default output, which is stderr. iconic default behavior tbh.

Parameters

  • f β€” pointer to the stream.

Returns

  • 0 on success. πŸŽ€
  • negative on error. 😭

FILE * rte_log_get_stream (void )

Grab the stream the logging system is currently using. (peep rte_openlog_stream() if you wanna change it instead β€” different function, different mood.)

Returns

  • pointer to the stream. ✨

void rte_log_set_global_level (uint32_t level)

Set the global log level, the main character of log levels. πŸ‘‘

after you call this, any log with a level lower or equal to the level you passed will actually show up. so like, it's a cutoff, and everything at or below it gets the green light.

Parameters

  • level β€” log level. a value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).

uint32_t rte_log_get_global_level (void )

Read the current global log level. no cap, it's just a getter.

Returns

  • the current global log level. πŸ’œ

int rte_log_get_level (uint32_t logtype)

Get the log level for one specific type.

Parameters

  • logtype β€” the log type identifier.

Returns

  • 0 on success, or a negative value if logtype is invalid. πŸ™‚β†’πŸ˜

bool rte_log_can_log (uint32_t logtype, uint32_t loglevel)

Vibe check for a single log: given a logtype, can a log at this loglevel actually get printed? 🫢

Parameters

  • logtype β€” the log type identifier
  • loglevel β€” log level. a value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).

Returns

  • returns 'true' if the log can be printed and 'false' if it can't. simple as that bestie.

int rte_log_set_level_pattern (const char * pattern, uint32_t level)

Set the log level for a type, but you find that type using a globbing pattern. fancy. 🌸

Parameters

  • pattern β€” the globbing pattern identifying the log type.
  • level β€” the level to be set.

Returns

  • 0 on success, a negative value if level is invalid.

int rte_log_set_level_regexp (const char * regex, uint32_t level)

Same energy as above, except you're matching with a regular expression. iykyk. πŸ’…

Parameters

  • regex β€” the regular expression identifying the log type.
  • level β€” the level to be set.

Returns

  • 0 on success, a negative value if level is invalid.

int rte_log_set_level (uint32_t logtype, uint32_t level)

Set the log level for a given type, the straightforward version.

Parameters

  • logtype β€” the log type identifier.
  • level β€” the level to be set.

Returns

  • 0 on success, a negative value if logtype or level is invalid. πŸ“

int rte_log_cur_msg_loglevel (void )

Get the current loglevel of the message that's being processed right now. ⭐

here's the tea: before the log subsystem calls your user-defined stream for logging, it sets a per-lcore variable holding the loglevel and the logtype of the message currently being processed. your user-defined log output function can get at that info through this function. slay.

Returns

  • the loglevel of the message being processed. πŸ’–

int rte_log_cur_msg_logtype (void )

Get the current logtype of the message being processed right now.

same lore as its sibling above 🧚 β€” before calling the user-defined stream for logging, the log subsystem sets a per-lcore variable with the loglevel and the logtype of the message being processed, and your user-defined log output function can reach that info via this function.

Returns

  • the logtype of the message being processed. 🌈

int rte_log_register (const char * name)

Register a dynamic log type. πŸ’œ

btw if a log is already registered with that same type, the returned value is the same as the previous one. no duplicates, no drama.

Parameters

  • name β€” the string identifying the log type.

Returns

  • >0: success, and the returned value is the log type identifier. πŸ‘‘
  • (-ENOMEM): cannot allocate memory. πŸ’€

int rte_log_register_type_and_pick_level (const char * name, uint32_t level_def)

Register a dynamic log type and try to pick its level from the EAL options. two birds, one function. πŸ¦‹

rte_log_register() gets called inside this one. if that works out, the function tries to search for a matching regexp in the list of EAL log level options and grabs the level from the last matching entry. and if literally nothing from the list applies? the level gets set to your user-defined default value. periodt.

Parameters

  • name β€” name for the log type to be registered
  • level_def β€” fallback level to be set if the global list has no matching options

Returns

  • >=0: the newly registered log type ✨
  • <0: rte_log_register() error value 😭

void rte_log_list_types (FILE * out, const char * prefix)

Dump the name of each logtype, one per line. a whole lineup. πŸŽ€

Parameters

  • out β€” stream where the list is sent.
  • prefix β€” string preceding each logtype in the output.

void rte_log_dump (FILE * f)

Dump log information. πŸ’…

specifically: it dumps the global level and the registered log types. the whole receipts folder, basically.

Parameters

  • f β€” the output stream where the dump should be sent.

int rte_log (uint32_t level, uint32_t logtype, const char * format, ...)

Generate a log message!! the big one!! 🌈

the message gets sent into the stream defined by the previous call to rte_openlog_stream().

the level argument decides whether the log actually gets displayed or not, based on your loglevel settings. gatekeeping, but make it config.

preferred alternative is RTE_LOG() because it adds the level and type into the logged string. just saying. πŸ™ˆ

Parameters

  • level β€” log level. a value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
  • logtype β€” the log type, for example, RTE_LOGTYPE_EAL.
  • format β€” the format string, as in printf(3), followed by the variable arguments required by the format.

Returns

  • 0: Success. πŸ”₯
  • negative on error. 😭

int int rte_vlog (uint32_t level, uint32_t logtype, const char * format, va_list ap)

Generate a log message β€” the va_list edition. πŸ’–

the message goes into the stream defined by the previous call to rte_openlog_stream().

the level argument figures out if the log gets displayed or not, depending on your loglevel settings. also, a trailing newline may be added if needed. cute little touch.

preferred alternative is RTE_LOG() because it adds the level and type into the logged string. same disclaimer as before, bestie. ✨

Parameters

  • level β€” log level. a value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8).
  • logtype β€” the log type, for example, RTE_LOGTYPE_EAL.
  • format β€” the format string, as in printf(3), followed by the variable arguments required by the format.
  • ap β€” the va_list of the variable arguments required by the format.

Returns

  • 0: Success. πŸŽ€
  • negative on error. πŸ’€

✨ AUTHOR ✨

Generated automatically by Doxygen for DPDK from the source code. πŸ€– (yes the docs wrote themselves, no thoughts, just Doxygen doing its thing πŸ’…)


aaaand that's a wrap on rte_log.h(3) bestie!! πŸŽ‰ this whole beautiful mess came from DPDK, Version 25.11.3, dated rte_log.h(3) β€” go forth and log responsibly, the vibes are immaculate, the levels are set, periodt. πŸ’–βœ¨πŸ¦‹πŸŒΈπŸ‘‘

πŸ“¦ where this page comes from