Skip to content

Add kconfig templates to avoid code repetition #9761

@nordic-krch

Description

@nordic-krch

Many modules (ideally all) has own, unique logging level configuration in kconfig. From user perspective this configuration should look the same for each module (choice vs raw int, configuration message, help, etc.). Ideally there should be some way of defining template or macro. It could be generic or log specific if we don't see other use case.

It could be something like:

macro LOG_CONFIG(MODULE, module_str)
choice
prompt "<module_str> logging level"

config <MODULE>_LOG_LEVEL_OFF
bool "Off"
config <MODULE>_LOG_LEVEL_ERR
bool "Error"
config <MODULE>_LOG_LEVEL_WRN
bool "Warning"
config <MODULE>_LOG_LEVEL_INF
bool "Info"
config <MODULE>_LOG_LEVEL_DBG
bool "Debug"
endchoice

config <MODULE>_LOG_LEVEL
int
default 0 if <MODULE>_LOG_LEVEL_OFF
default 1 if <MODULE>_LOG_LEVEL_ERR
default 2 if <MODULE>_LOG_LEVEL_WRN
default 3 if <MODULE>_LOG_LEVEL_INF
default 4 if <MODULE>_LOG_LEVEL_DBG

endmacro

Usage:

source "subsys/logging/Kconfig.log_macro"
LOG_CONFIG(BLUETOOTH_LL, Bluetooth link layer)

Initially it was proposed in the following review:
#8816 (comment)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions