From 48a9df043df64887cb99e03d7613379c947d11d8 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Tue, 17 Feb 2026 11:57:52 +0100 Subject: Add configurable log level as optional CLI argument All three programs now accept an optional second argument [log-level] (trace, debug, info, warning, error, fatal) defaulting to info. The level is applied by setting the logger context pointer directly, avoiding a memory leak that would occur from overwriting the heap-allocated logger struct. Also documents the ASan leak-check workflow in CLAUDE.md. --- src/common.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index d102868..7d378f1 100644 --- a/src/common.c +++ b/src/common.c @@ -59,6 +59,26 @@ loadFile (const char *const path) * Security Helpers * ======================================================================== */ +int +parseLogLevel (const char *name) +{ + static const struct + { + const char *name; + UA_LogLevel level; + } levels[] = { + { "trace", UA_LOGLEVEL_TRACE }, { "debug", UA_LOGLEVEL_DEBUG }, + { "info", UA_LOGLEVEL_INFO }, { "warning", UA_LOGLEVEL_WARNING }, + { "error", UA_LOGLEVEL_ERROR }, { "fatal", UA_LOGLEVEL_FATAL }, + }; + for (size_t i = 0; i < sizeof (levels) / sizeof (levels[0]); i++) + { + if (strcmp (name, levels[i].name) == 0) + return (int)levels[i].level; + } + return -1; +} + UA_MessageSecurityMode parseSecurityMode (const char *name) { -- cgit v1.2.3