Custom logger

Skip to first unread message

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;

    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.

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

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

francois vandewalle

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

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

if I identified this correctly the mentioned PR is this:
Which was not merged.
But a lot of other logging related PRs were merged:

Hope this helps?

Reply all
Reply to author
0 new messages