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/client_find_servers.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/client_find_servers.c') diff --git a/src/client_find_servers.c b/src/client_find_servers.c index e50623f..a85b63f 100644 --- a/src/client_find_servers.c +++ b/src/client_find_servers.c @@ -211,10 +211,21 @@ readServerTime (UA_Client *client, int main (int argc, char **argv) { - if (argc != 2) + if (argc < 2 || argc > 3) { UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, - "Usage: %s ", argv[0]); + "Usage: %s [log-level]", argv[0]); + return EXIT_FAILURE; + } + + const char *logLevelStr = (argc == 3) ? argv[2] : "info"; + int logLevel = parseLogLevel (logLevelStr); + if (logLevel < 0) + { + UA_LOG_FATAL (UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, + "Unknown log level: %s " + "(expected trace, debug, info, warning, error, fatal)", + logLevelStr); return EXIT_FAILURE; } @@ -302,6 +313,8 @@ main (int argc, char **argv) configFree (&cfg); return EXIT_FAILURE; } + UA_ClientConfig *clientConfig = UA_Client_getConfig (client); + clientConfig->logging->context = (void *)(uintptr_t)logLevel; UA_ApplicationDescription *applicationDescriptionArray = NULL; size_t applicationDescriptionArraySize = 0; -- cgit v1.2.3