Custom logger

39 views
Skip to first unread message

giusgu...@gmail.com

unread,
Feb 13, 2020, 1:26:57 PM2/13/20
to open62541

Hi all,
I am using open62541 1.0.1 (mainly the server part), and I am facing a (very small) problem. I'd like to redirect all logs to my custom logger, but when I initialize a basic server configuration a the library produce a message (a warning about security options) directly by UA_Log_Stdout_ logger. UA_Log_Stdout_ structure is public, but read-only, so I can't alter it by code (at least, not in a clean way). The best I managed to do is redirect all but the very first message by changing the "logger" filed in configuration before creating the server:

    static UA_ServerConfig cfg;
    UA_ServerConfig_setDefault(&cfg);

    cfg.logger = my_logger;
    UA_Log_Stdout = &cfg.logger;

    UA_Server *server = UA_Server_newWithConfig(&cfg);

I couldn't a way to work around this issue without modifying the library. Any ideas?

Anyway, I suggest to add to the library a "general init" function (and a "general deinit", too); users should call it before using any other one. The function could accept some global configuration parameters, e.g. the custom logger. This could also help in better managemet of system resources (e.g. under Windows, call to WSAStartup only once; indeed it seems to me that it gets called each time a client connection is required in the current implementation). Another thing that the function could do is register a custom malloc/free.




giusgu...@gmail.com

unread,
Feb 18, 2020, 12:37:58 PM2/18/20
to open62541


I eventually decided to patch the sorce. Pull request pending.

francois vandewalle

unread,
Jul 27, 2022, 3:31:07 AMJul 27
to open62541
Hi !

I would need exactly that possibility for my project.
I see that this message is a few years old, is there meanwhile a solution in the current open62541 release ?


Best regards,

François Vandewalle

Götz Görisch

unread,
Jul 27, 2022, 4:14:59 AMJul 27
to open62541
Hi, 

if I identified this correctly the mentioned PR is this: https://github.com/open62541/open62541/pull/3449
Which was not merged.
But a lot of other logging related PRs were merged:

https://github.com/open62541/open62541/pulls?q=is%3Apr+is%3Aclosed+logger

Hope this helps?
Götz

Reply all
Reply to author
Forward
0 new messages