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/server_register.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/server_register.c')
| -rw-r--r-- | src/server_register.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/server_register.c b/src/server_register.c index ae8e959..5bdba8e 100644 --- a/src/server_register.c +++ b/src/server_register.c @@ -42,10 +42,21 @@ main (int argc, char **argv) signal (SIGINT, stopHandler); signal (SIGTERM, stopHandler); - 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; } @@ -182,6 +193,7 @@ main (int argc, char **argv) } UA_ServerConfig *serverConfig = UA_Server_getConfig (server); + serverConfig->logging->context = (void *)(uintptr_t)logLevel; /* Configure access control after server creation because UA_ServerConfig_setDefaultWithSecurityPolicies (called by @@ -224,6 +236,7 @@ main (int argc, char **argv) configFree (&cfg); return EXIT_FAILURE; } + clientConfig.logging->context = (void *)(uintptr_t)logLevel; if (clientUsername) UA_ClientConfig_setAuthenticationUsername (&clientConfig, clientUsername, clientPassword); @@ -254,6 +267,7 @@ main (int argc, char **argv) trustPaths, trustSize, securityMode, securityPolicyUri); if (retval == UA_STATUSCODE_GOOD) { + clientConfig.logging->context = (void *)(uintptr_t)logLevel; if (clientUsername) UA_ClientConfig_setAuthenticationUsername ( &clientConfig, clientUsername, clientPassword); @@ -278,6 +292,7 @@ main (int argc, char **argv) trustSize, securityMode, securityPolicyUri); if (retval == UA_STATUSCODE_GOOD) { + clientConfig.logging->context = (void *)(uintptr_t)logLevel; if (clientUsername) UA_ClientConfig_setAuthenticationUsername ( &clientConfig, clientUsername, clientPassword); |
