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

Randy L Tice rtice at cisco.com
Thu Nov 19 19:05:01 CET 2026


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>
---
 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                          | 20 ++++++++++++++++++++
 lib/log/rte_log.h                      | 25 +++++++++++++++++++++++++
 5 files changed, 68 insertions(+)

diff --git a/app/test/test_logs.c b/app/test/test_logs.c
index 375b06a1b7..3f978b42d9 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_NULL(rte_log_get_level_name(UINT32_MAX),
+		"invalid log level has a name\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 8387949ef3..f8bfdd4ce4 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..8e4aeedfd6 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -126,6 +126,26 @@ 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)
+{
+	if (level > RTE_LOG_MAX)
+		return NULL;
+
+	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..bd15022b07 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 NULL if level is not valid.
+ *   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



More information about the dev mailing list