Use different logging modules with different log levels

Hello,

I want to use standalone logging for each file (/module)(/driver) of my program, therefore register different logging modules with different log levels each.
Registering modules isn't the problem, but if I initialize different modules their log levels interfere with each other and I want to be able to change log levels for each file/module.

Im initializing the modules with:

#include <logging/log.h>
LOG_MODULE_REGISTER(name, LOG_LEVEL_X);

where name is different for each file/module. I've also tried to work around with using

LOG_MODULE_DECLARE(name, LOG_LEVEL_X);

but didn't get it working. Either I see no logs or I see all of them.

Thanks for your help.

nRF Connect SDK Version: v2.1.0-rc2
Evalboard: nrf9160dk

Parents
  • Hi,

    You can register multiple log modules, with their own log level.

    You can see how this can be done in the asset_tracker_v2 application.

    E.g in main.c you have

    #include <zephyr/logging/log.h>
    #include <zephyr/logging/log_ctrl.h>
    
    LOG_MODULE_REGISTER(MODULE, CONFIG_APPLICATION_MODULE_LOG_LEVEL);

    while in watchdog/watchdog_app.c you have

    #include <zephyr/logging/log.h>
    LOG_MODULE_REGISTER(watchdog, CONFIG_WATCHDOG_LOG_LEVEL);

    CONFIG_APPLICATION_MODULE_LOG_LEVEL and CONFIG_WATCHDOG_LOG_LEVEL is defined by the the project Kconfig and src/watchdog/Kconfig respectively

    module = APPLICATION_MODULE
    module-str = Application module
    source "subsys/logging/Kconfig.template.log_config"

    module = WATCHDOG
    module-str = Watchdog
    source "subsys/logging/Kconfig.template.log_config"

    Best regards,

    Didrik

Reply
  • Hi,

    You can register multiple log modules, with their own log level.

    You can see how this can be done in the asset_tracker_v2 application.

    E.g in main.c you have

    #include <zephyr/logging/log.h>
    #include <zephyr/logging/log_ctrl.h>
    
    LOG_MODULE_REGISTER(MODULE, CONFIG_APPLICATION_MODULE_LOG_LEVEL);

    while in watchdog/watchdog_app.c you have

    #include <zephyr/logging/log.h>
    LOG_MODULE_REGISTER(watchdog, CONFIG_WATCHDOG_LOG_LEVEL);

    CONFIG_APPLICATION_MODULE_LOG_LEVEL and CONFIG_WATCHDOG_LOG_LEVEL is defined by the the project Kconfig and src/watchdog/Kconfig respectively

    module = APPLICATION_MODULE
    module-str = Application module
    source "subsys/logging/Kconfig.template.log_config"

    module = WATCHDOG
    module-str = Watchdog
    source "subsys/logging/Kconfig.template.log_config"

    Best regards,

    Didrik

Children
No Data
Related