[PATCH 1/1] log: add name query functions

Stephen Hemminger stephen at networkplumber.org
Mon Nov 16 20:05:59 CET 2026


On Thu, 22 Oct 2026 14:41:12 -0400
Randy L Tice <rtice at cisco.com> wrote:

> From: Randy L Tice <rtice at cisco.com>
> Date: Thu, 22 Oct 2026 14:34:31 -0400
> 
> Applications can query the numeric level for a log type, but cannot map
> a level or type identifier back to a human-readable name without parsing
> log dump output.
> 
> Add experimental helpers for retrieving the canonical level name and the
> registered log type name. Document ownership of the returned strings and
> add unit test coverage.
> 
> The original downstream implementation was authored by Walt Robinson
> <walrobin at cisco.com>.
> 
> Signed-off-by: Randy L Tice <rtice at cisco.com>
> ---

Finally got around to looking at this, I think it is OK.
But AI had a good suggestion about making error returns the same.

Review: [PATCH 1/1] log: add name query functions

Applies cleanly to main. Builds with -Dwerror=true including
app/test.

Warning
-------

Patch 1/1: inconsistent error convention between the two getters.

rte_log_get_type_name() returns NULL for an invalid type, but
rte_log_get_level_name() returns the string "unknown" for an invalid
level. A caller cannot tell an out-of-range level from a real one
without comparing against a magic string, and the public API now
inherits whatever eal_log_level2str() (an internal symbol) chooses
to return. Return NULL for both:

const char *
rte_log_get_level_name(uint32_t level)
{
	if (level > RTE_LOG_MAX)
		return NULL;

	return eal_log_level2str(level);
}

and in rte_log.h:

 * @return
 *   The name of the log level, or NULL if level is not valid.

The test then becomes:

	TEST_ASSERT_NULL(rte_log_get_level_name(UINT32_MAX),
		"invalid log level has a name\n");


More information about the dev mailing list