* [PATCH 0/1] log: add name query functions
@ 2026-10-22 18:41 Randy L Tice
2026-10-22 18:41 ` [PATCH 1/1] " Randy L Tice
2026-11-02 18:52 ` [PATCH 0/1] " Randy L Tice
0 siblings, 2 replies; 5+ messages in thread
From: Randy L Tice @ 2026-10-22 18:41 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
Applications that display or export DPDK logging configuration can query
numeric log levels, but have no direct way to retrieve the corresponding
level and component names. They must currently duplicate the level mapping
and cannot safely query a registered component name.
Add experimental APIs to return the canonical name for a log level and the
registered name for a log type. The returned strings are const and remain
owned by DPDK. Unit tests cover known and unknown levels and types, and the
new APIs are documented in the programmer guide and release notes.
The original downstream implementation was authored by Walt Robinson.
Validation:
- Full native Meson/Ninja build
- DPDK fast-tests / logs_autotest
Randy Tice (1):
log: add name query functions
app/test/test_logs.c | 11 +++++++++++
doc/guides/prog_guide/log_lib.rst | 7 +++++++
doc/guides/rel_notes/release_26_11.rst | 5 +++++
lib/log/log.c | 17 +++++++++++++++++
lib/log/rte_log.h | 25 +++++++++++++++++++++++++
5 files changed, 65 insertions(+)
--
2.35.6
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/1] log: add name query functions
2026-10-22 18:41 [PATCH 0/1] log: add name query functions Randy L Tice
@ 2026-10-22 18:41 ` Randy L Tice
2026-11-12 14:01 ` Randy L Tice
2026-11-16 19:05 ` Stephen Hemminger
2026-11-02 18:52 ` [PATCH 0/1] " Randy L Tice
1 sibling, 2 replies; 5+ messages in thread
From: Randy L Tice @ 2026-10-22 18:41 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
From: Randy L Tice <rtice@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@cisco.com>.
Signed-off-by: Randy L Tice <rtice@cisco.com>
---
app/test/test_logs.c | 11 +++++++++++
doc/guides/prog_guide/log_lib.rst | 7 +++++++
doc/guides/rel_notes/release_26_11.rst | 5 +++++
lib/log/log.c | 17 +++++++++++++++++
lib/log/rte_log.h | 25 +++++++++++++++++++++++++
5 files changed, 65 insertions(+)
diff --git a/app/test/test_logs.c b/app/test/test_logs.c
index 375b06a1b7..ecc9f36f47 100644
--- a/app/test/test_logs.c
+++ b/app/test/test_logs.c
@@ -110,6 +110,17 @@ test_logs(void)
"invalid default level for logtype3 got %d, expecting %d\n",
ret, RTE_LOG_ERR);
+ TEST_ASSERT(strcmp(rte_log_get_level_name(RTE_LOG_ERR), "error") == 0,
+ "invalid name for error log level\n");
+ TEST_ASSERT(strcmp(rte_log_get_level_name(0), "disabled") == 0,
+ "invalid name for disabled log level\n");
+ TEST_ASSERT(strcmp(rte_log_get_level_name(UINT32_MAX), "unknown") == 0,
+ "invalid name for unknown log level\n");
+ TEST_ASSERT(strcmp(rte_log_get_type_name(logtype1), "logtype1") == 0,
+ "invalid name for logtype1\n");
+ TEST_ASSERT_NULL(rte_log_get_type_name(UINT32_MAX),
+ "invalid log type has a name\n");
+
rte_log_set_level(logtype1, RTE_LOG_ERR);
CHECK_LEVELS(RTE_LOG_ERR, RTE_LOG_INFO, RTE_LOG_ERR);
diff --git a/doc/guides/prog_guide/log_lib.rst b/doc/guides/prog_guide/log_lib.rst
index 67b9ec75cd..1251127a53 100644
--- a/doc/guides/prog_guide/log_lib.rst
+++ b/doc/guides/prog_guide/log_lib.rst
@@ -60,6 +60,13 @@ For example::
Within an application, the same result can be achieved by using the ``rte_log_set_level_pattern()`` or ``rte_log_set_level_regex()`` APIs.
+Querying Log Names
+~~~~~~~~~~~~~~~~~~
+
+Applications can use ``rte_log_get_level_name()`` to convert a numeric log level
+to its display name, and ``rte_log_get_type_name()`` to retrieve the registered
+name for a log component type.
+
Using Logging APIs to Generate Log Messages
-------------------------------------------
diff --git a/doc/guides/rel_notes/release_26_11.rst b/doc/guides/rel_notes/release_26_11.rst
index be758a0c02..fac585ddd1 100644
--- a/doc/guides/rel_notes/release_26_11.rst
+++ b/doc/guides/rel_notes/release_26_11.rst
@@ -73,6 +73,11 @@ New Features
Added the experimental ``rte_cpu_socket_id()`` function
to map an OS logical CPU ID to the NUMA socket containing that CPU.
+* **Added APIs to get log level and type names.**
+
+ Added the experimental ``rte_log_get_level_name()`` and
+ ``rte_log_get_type_name()`` functions to query human-readable log names.
+
* **Added pile stack and mempool driver.**
Introduced pile, a lock-free, stack-like implementation,
diff --git a/lib/log/log.c b/lib/log/log.c
index 8ad5250a13..a4ecfa0436 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -126,6 +126,23 @@ rte_log_get_level(uint32_t type)
return rte_logs.dynamic_types[type].loglevel;
}
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_log_get_level_name, 26.11)
+const char *
+rte_log_get_level_name(uint32_t level)
+{
+ return eal_log_level2str(level);
+}
+
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_log_get_type_name, 26.11)
+const char *
+rte_log_get_type_name(uint32_t type)
+{
+ if (type >= rte_logs.dynamic_types_len)
+ return NULL;
+
+ return rte_logs.dynamic_types[type].name;
+}
+
RTE_EXPORT_SYMBOL(rte_log_can_log)
bool
rte_log_can_log(uint32_t logtype, uint32_t level)
diff --git a/lib/log/rte_log.h b/lib/log/rte_log.h
index 3735137150..e7a0349b6e 100644
--- a/lib/log/rte_log.h
+++ b/lib/log/rte_log.h
@@ -126,6 +126,31 @@ uint32_t rte_log_get_global_level(void);
*/
int rte_log_get_level(uint32_t logtype);
+/**
+ * Get the name of a log level.
+ *
+ * @param level
+ * The log level identifier.
+ * @return
+ * The name of the log level, or "unknown" if level is not recognized.
+ * The returned string is owned by DPDK and must not be modified or freed.
+ */
+__rte_experimental
+const char *rte_log_get_level_name(uint32_t level);
+
+/**
+ * Get the name of a log type.
+ *
+ * @param logtype
+ * The log type identifier.
+ * @return
+ * The name of the log type, or NULL if logtype is not registered.
+ * The returned string is owned by DPDK, remains valid for the lifetime of
+ * the process, and must not be modified or freed.
+ */
+__rte_experimental
+const char *rte_log_get_type_name(uint32_t logtype);
+
/**
* For a given `logtype`, check if a log with `loglevel` can be printed.
*
--
2.35.6
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/1] log: add name query functions
2026-10-22 18:41 [PATCH 0/1] log: add name query functions Randy L Tice
2026-10-22 18:41 ` [PATCH 1/1] " Randy L Tice
@ 2026-11-02 18:52 ` Randy L Tice
1 sibling, 0 replies; 5+ messages in thread
From: Randy L Tice @ 2026-11-02 18:52 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
friendly nudge
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] log: add name query functions
2026-10-22 18:41 ` [PATCH 1/1] " Randy L Tice
@ 2026-11-12 14:01 ` Randy L Tice
2026-11-16 19:05 ` Stephen Hemminger
1 sibling, 0 replies; 5+ messages in thread
From: Randy L Tice @ 2026-11-12 14:01 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev
Hi Stephen,
Could you take a look at this patch when you have a chance? It is still
applicable, and the automated checks are green. I'm happy to revise the API
or implementation if you would prefer a different direction.
Thanks,
Randy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] log: add name query functions
2026-10-22 18:41 ` [PATCH 1/1] " Randy L Tice
2026-11-12 14:01 ` Randy L Tice
@ 2026-11-16 19:05 ` Stephen Hemminger
1 sibling, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2026-11-16 19:05 UTC (permalink / raw)
To: Randy L Tice; +Cc: dev
On Thu, 22 Oct 2026 14:41:12 -0400
Randy L Tice <rtice@cisco.com> wrote:
> From: Randy L Tice <rtice@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@cisco.com>.
>
> Signed-off-by: Randy L Tice <rtice@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");
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-16 19:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 18:41 [PATCH 0/1] log: add name query functions Randy L Tice
2026-10-22 18:41 ` [PATCH 1/1] " Randy L Tice
2026-11-12 14:01 ` Randy L Tice
2026-11-16 19:05 ` Stephen Hemminger
2026-11-02 18:52 ` [PATCH 0/1] " Randy L Tice
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox