From 9ba540ec8c411a78b45e5a70f826b483009e529b Mon Sep 17 00:00:00 2001 From: Daniel Fanache Date: Tue, 1 Dec 2020 12:42:06 +0000 Subject: [PATCH] Configurable log levels for all the modules using Zephyr's logging. This allows us to enable e.g debug output for the CAN module with CONFIG_CAN_LOG_LEVEL=4 without enabling the global CONFIG_LOG_DEFAULT_LEVEL=4 and being swamped with debug output from all of Zephyr's subsytems. --- src/bat_charger.cpp | 2 +- src/daq.cpp | 2 +- src/data_nodes.cpp | 2 +- src/dcdc.cpp | 4 ++-- src/ext/can.cpp | 2 +- src/hardware.cpp | 2 +- src/pwm_switch.cpp | 2 +- zephyr/Kconfig | 53 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/bat_charger.cpp b/src/bat_charger.cpp index 7ab34f5..d90551a 100644 --- a/src/bat_charger.cpp +++ b/src/bat_charger.cpp @@ -10,7 +10,7 @@ #ifndef UNIT_TEST #include -LOG_MODULE_REGISTER(bat_charger, CONFIG_LOG_DEFAULT_LEVEL); +LOG_MODULE_REGISTER(bat_charger, CONFIG_BAT_LOG_LEVEL); #endif #include // for fabs function diff --git a/src/daq.cpp b/src/daq.cpp index e638c11..1f6890a 100644 --- a/src/daq.cpp +++ b/src/daq.cpp @@ -10,7 +10,7 @@ #ifndef UNIT_TEST #include -LOG_MODULE_REGISTER(daq, CONFIG_LOG_DEFAULT_LEVEL); +LOG_MODULE_REGISTER(daq, CONFIG_DAQ_LOG_LEVEL); #endif #include // log for thermistor calculation diff --git a/src/data_nodes.cpp b/src/data_nodes.cpp index 880916d..9b9ed59 100644 --- a/src/data_nodes.cpp +++ b/src/data_nodes.cpp @@ -11,7 +11,7 @@ #include #include #include -LOG_MODULE_REGISTER(data_nodes, CONFIG_LOG_DEFAULT_LEVEL); +LOG_MODULE_REGISTER(data_nodes, CONFIG_DATA_NODES_LOG_LEVEL); #endif #include diff --git a/src/dcdc.cpp b/src/dcdc.cpp index bfcffa8..0c09e71 100644 --- a/src/dcdc.cpp +++ b/src/dcdc.cpp @@ -12,7 +12,7 @@ #include #include -LOG_MODULE_REGISTER(dcdc, CONFIG_LOG_DEFAULT_LEVEL); +LOG_MODULE_REGISTER(dcdc, CONFIG_DCDC_LOG_LEVEL); #endif #include // for fabs function @@ -128,7 +128,7 @@ int Dcdc::perturb_observe_controller() pwr_inc_goal = pwm_delta; } -#if CONFIG_LOG_DEFAULT_LEVEL == LOG_LEVEL_DBG +#if CONFIG_DCDC_LOG_LEVEL == LOG_LEVEL_DBG // workaround as LOG_DBG does not support float printing printf("P: %.2fW (prev %.2fW), ind. current: %.2f, " "in: %.2fV, %.2fA margin, out: %.2fV (target %.2fV), %.2fA margin, " diff --git a/src/ext/can.cpp b/src/ext/can.cpp index 708780b..668ee9d 100644 --- a/src/ext/can.cpp +++ b/src/ext/can.cpp @@ -16,7 +16,7 @@ #endif #include -LOG_MODULE_REGISTER(ext_can, CONFIG_LOG_DEFAULT_LEVEL); +LOG_MODULE_REGISTER(ext_can, CONFIG_CAN_LOG_LEVEL); #include "hardware.h" // for software watchdog diff --git a/src/hardware.cpp b/src/hardware.cpp index a96aa8c..d27f5ce 100644 --- a/src/hardware.cpp +++ b/src/hardware.cpp @@ -34,7 +34,7 @@ #include #include -LOG_MODULE_REGISTER(hardware, CONFIG_LOG_DEFAULT_LEVEL); +LOG_MODULE_REGISTER(hardware, CONFIG_HW_LOG_LEVEL); #define MAX_SW_WDT_CHANNELS 5 diff --git a/src/pwm_switch.cpp b/src/pwm_switch.cpp index cd6be6f..a162d06 100644 --- a/src/pwm_switch.cpp +++ b/src/pwm_switch.cpp @@ -10,7 +10,7 @@ #ifndef UNIT_TEST #include -LOG_MODULE_REGISTER(pwm_switch, CONFIG_LOG_DEFAULT_LEVEL); +LOG_MODULE_REGISTER(pwm_switch, CONFIG_PWM_LOG_LEVEL); #endif #include diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 113d6ff..5c94233 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -370,6 +370,59 @@ config THINGSET_MAKER_PASSWORD endmenu # ThingSet interfaces +menu "Logging setup" + +config CAN_LOG_LEVEL + int "Log level for the CAN module (if included)" + default 2 + depends on LOG + help + Log level for the CAN module (if included). 0=off, 1=ERR, 2=WRN, 3=INF, 4=DBG + +config DAQ_LOG_LEVEL + int "Log level for the DAQ module" + default 2 + depends on LOG + help + Log level for the DAQ module. 0=off, 1=ERR, 2=WRN, 3=INF, 4=DBG + +config DATA_NODES_LOG_LEVEL + int "Log level for the data nodes module" + default 2 + depends on LOG + help + Log level for the data nodes module. 0=off, 1=ERR, 2=WRN, 3=INF, 4=DBG + + +config DCDC_LOG_LEVEL + int "Log level for the DCDC module (if included)" + default 2 + depends on LOG + help + Log level for the DCDC module (if included). 0=off, 1=ERR, 2=WRN, 3=INF, 4=DBG + +config HW_LOG_LEVEL + int "Log level for the hardware module" + default 2 + depends on LOG + help + Log level for the hardware module. 0=off, 1=ERR, 2=WRN, 3=INF, 4=DBG + +config BAT_LOG_LEVEL + int "Log level for the battery module" + default 2 + depends on LOG + help + Log level for the battery module. 0=off, 1=ERR, 2=WRN, 3=INF, 4=DBG + +config PWM_LOG_LEVEL + int "Log level for the PWM module (if included)" + default 2 + depends on LOG + help + Log level for the PWM module (if included). 0=off, 1=ERR, 2=WRN, 3=INF, 4=DBG + +endmenu # Logging setup menuconfig CUSTOMIZATION bool "Firmware customization"