diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 11:57:52 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 11:57:52 +0100 |
| commit | 48a9df043df64887cb99e03d7613379c947d11d8 (patch) | |
| tree | 897d94bcc55c481a82878c5d2de5ec3369df33ed /src/client_find_servers.c | |
| parent | a54421dd976fd8081e96c11c2621076876c9986b (diff) | |
| download | BobinkCOpcUa-48a9df043df64887cb99e03d7613379c947d11d8.tar.gz BobinkCOpcUa-48a9df043df64887cb99e03d7613379c947d11d8.zip | |
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.
Diffstat (limited to 'src/client_find_servers.c')
| -rw-r--r-- | src/client_find_servers.c | 17 |
1 files changed, 15 insertions, 2 deletions
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 <config-file>", argv[0]); + "Usage: %s <config-file> [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; |
