Skip to content

Compiling debug logs, but set log level to info by default #57957

Closed Answered by toonst
toonst asked this question in Q&A
Discussion options

You must be logged in to vote

It seems there is no way to do this through Kconfig alone. The solution was to set the log levels at runtime from application code.

#include <zephyr/init.h>
#include <zephyr/logging/log_ctrl.h>

typedef struct {
    const char* module;
    uint32_t level;
} log_module_t;

static log_module_t log_modules[] = {
    {"net_if", LOG_LEVEL_INF},
    {"net_ethernet", LOG_LEVEL_INF},
    // add more modules as needed
};

static int set_initial_log_levels(const struct device *dev)
{
    ARG_UNUSED(dev);

    for (unsigned int i = 0; i < ARRAY_SIZE(log_modules); i++) {
        int source_id = log_source_id_get(log_modules[i].module);
        if (source_id < 0) {
            printk("Error: Log modul…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aburo8
Comment options

Answer selected by toonst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants