mdavidsaver / pvxs

PVA protocol client/server library and utilities.
https://mdavidsaver.github.io/pvxs/
Other
19 stars 25 forks source link

Logger set not working as expected #16

Closed thomasms closed 1 year ago

thomasms commented 3 years ago

Not sure if I am using the logger API correctly, but following the documentation and looking in the code I have tried to do a simple test with the logger, as below:


    DEFINE_LOGGER(mylogger, "MyLogger");

    // all fine
    assert(mylogger.test(pvxs::Level::Debug) == false);
    assert(mylogger.test(pvxs::Level::Err) == true);

    // all fine, but logger doesn't exist - not throwing....
    logger_level_set("LoggerDoesNotExist", pvxs::Level::Debug);
    log_debug_printf(mylogger, "Should not show!!\n", 0);
    log_err_printf(mylogger, "Should show!!\n", 0);

    // does not work
    logger_level_set("MyLogger", pvxs::Level::Debug);
    log_debug_printf(mylogger, "Should show but doesn't!!\n", 0);

    // but this works
    assert(mylogger.test(pvxs::Level::Debug) == false);
    mylogger.lvl = pvxs::Level::Debug;
    assert(mylogger.test(pvxs::Level::Debug) == true);
    // awkward that I need to give an argument (0) since I format is not needed here.
    log_debug_printf(mylogger, "From MyLogger!!\n", 0);

My output is then:

2021-03-03T10:43:42.826120700 ERR MyLogger Should show!!
2021-03-03T10:43:42.826637000 DEBUG MyLogger From MyLogger!!

I did not set PVXS_LOG to see how the logger works without any environment variables.

Are there any unit tests for the logger that I can look at?

Any help on how to use the API for the logger would be appreciated.

mdavidsaver commented 3 years ago

Sorry, I must have missed a automatic email.

What you show looks like it should work. I guess I need some test coverage of the logging configuration...

mdavidsaver commented 3 years ago

Should be fixed by 3dcf2f59fe1a2859518faf947a345010556f20ae

mdavidsaver commented 3 years ago

Also worth noting that I've recently changed the default log level to Warn.

thomasms commented 3 years ago

Great, I forgot about this issue. Thanks for the fix.