From 514325b8b3da4cde620975fc42694df9a9fdc4fd Mon Sep 17 00:00:00 2001 From: Karl Fessel Date: Fri, 5 Aug 2022 17:46:48 +0200 Subject: [PATCH] sys/log: modularize log into log_color and log_printfnoformat - log_color: make log_write nonstatic - log_printfnoformat - apply module split to Kconfig --- makefiles/pseudomodules.inc.mk | 2 - sys/Kconfig | 16 +++++++- sys/Makefile | 3 -- sys/Makefile.include | 8 +++- sys/log/Kconfig | 36 ---------------- sys/log/Makefile | 3 -- sys/log/Makefile.include | 19 --------- sys/log_color/Kconfig | 16 ++++++++ sys/log_color/Makefile | 1 + sys/log_color/Makefile.include | 1 + sys/log_color/include/log_module.h | 41 +++++++++++++++++++ .../log_module.h => log_color/log_color.c} | 36 +++------------- sys/log_printfnoformat/Kconfig | 18 ++++++++ sys/log_printfnoformat/Makefile | 1 + sys/log_printfnoformat/Makefile.include | 1 + .../include}/log_module.h | 5 ++- 16 files changed, 109 insertions(+), 98 deletions(-) delete mode 100644 sys/log/Kconfig delete mode 100644 sys/log/Makefile delete mode 100644 sys/log/Makefile.include create mode 100644 sys/log_color/Kconfig create mode 100644 sys/log_color/Makefile create mode 100644 sys/log_color/Makefile.include create mode 100644 sys/log_color/include/log_module.h rename sys/{log/log_color/log_module.h => log_color/log_color.c} (74%) create mode 100644 sys/log_printfnoformat/Kconfig create mode 100644 sys/log_printfnoformat/Makefile create mode 100644 sys/log_printfnoformat/Makefile.include rename sys/{log/log_printfnoformat => log_printfnoformat/include}/log_module.h (86%) diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 64712a5f41..8ca9125b0e 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -175,8 +175,6 @@ PSEUDOMODULES += l2filter_blacklist PSEUDOMODULES += l2filter_whitelist PSEUDOMODULES += libstdcpp PSEUDOMODULES += log -PSEUDOMODULES += log_printfnoformat -PSEUDOMODULES += log_color PSEUDOMODULES += lora ## @defgroup pseudomodule_libc_gettimeofday libc_gettimeofday ## @brief Includes implementation of gettimeofday() diff --git a/sys/Kconfig b/sys/Kconfig index 7cebeaa6be..b152c32314 100644 --- a/sys/Kconfig +++ b/sys/Kconfig @@ -64,8 +64,16 @@ rsource "Kconfig.picolibc" endmenu # Libc + rsource "Kconfig.stdio" -rsource "log/Kconfig" +choice LOG + bool "Logging system override" + optional + #modules log_color and log_printfnoformat describe their options +endchoice + +rsource "log_color/Kconfig" +rsource "log_printfnoformat/Kconfig" rsource "luid/Kconfig" rsource "malloc_thread_safe/Kconfig" rsource "matstat/Kconfig" @@ -124,4 +132,10 @@ config MODULE_SYS help System module, it serves to pull in all the rest of system modules. +config MODULE_LOG + bool + help + Modules that override the default log implementation should select this. + For more information see core/include/log.h. + endmenu # System diff --git a/sys/Makefile b/sys/Makefile index fa3161616d..85c6fd1230 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -104,9 +104,6 @@ endif ifneq (,$(filter l2util,$(USEMODULE))) DIRS += net/link_layer/l2util endif -ifneq (,$(filter log_%,$(USEMODULE))) - DIRS += log -endif ifneq (,$(filter nanocoap,$(USEMODULE))) DIRS += net/application_layer/nanocoap endif diff --git a/sys/Makefile.include b/sys/Makefile.include index bad9ee6c1a..0a4fcbe837 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -74,8 +74,12 @@ ifneq (,$(filter embunit,$(USEMODULE))) endif endif -ifneq (,$(filter log_%,$(USEMODULE))) - include $(RIOTBASE)/sys/log/Makefile.include +ifneq (,$(filter log_color,$(USEMODULE))) + include $(RIOTBASE)/sys/log_color/Makefile.include +endif + +ifneq (,$(filter log_printfnoformat,$(USEMODULE))) + include $(RIOTBASE)/sys/log_printfnoformat/Makefile.include endif ifneq (,$(filter newlib,$(USEMODULE))) diff --git a/sys/log/Kconfig b/sys/log/Kconfig deleted file mode 100644 index c00efd5194..0000000000 --- a/sys/log/Kconfig +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (c) 2021 HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. -# - -choice - bool "Logging system override" - optional - depends on TEST_KCONFIG - help - Say y to override the default logging functions. For more information see - core/include/log.h. - -config MODULE_LOG_COLOR - bool "Colored output" - select MODULE_LOG - help - Implements a logging module with colored output. - -config MODULE_LOG_PRINTFNOFORMAT - bool "puts-based log" - select MODULE_LOG - help - Logging is implemented using puts instead of printf. Use it where printf - might be too heavy. This also serves as an example for logging - implementation. - -endchoice - -config MODULE_LOG - bool - help - Modules that override the default log implementation shoul select this. - For more information see core/include/log.h. diff --git a/sys/log/Makefile b/sys/log/Makefile deleted file mode 100644 index 6cd43be02c..0000000000 --- a/sys/log/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -DIRS += $(dir $(wildcard $(addsuffix /Makefile, $(USEMODULE)))) - -include $(RIOTBASE)/Makefile.base diff --git a/sys/log/Makefile.include b/sys/log/Makefile.include deleted file mode 100644 index b9d4614145..0000000000 --- a/sys/log/Makefile.include +++ /dev/null @@ -1,19 +0,0 @@ -# check that one, and only one log backend is being used -USED_LOG_BACKENDS := $(sort $(filter log_%,$(USEMODULE))) - -ifeq (0,$(words $(USED_LOG_BACKENDS))) - $(error The log module is being used but no backend is provided.) -else ifeq (1,$(words $(USED_LOG_BACKENDS))) - # only one backend is provided, this is correct -else - $(info Only one log backend can be used at a time.) - $(error Currently selecting: $(USED_LOG_BACKENDS)) -endif - -ifneq (,$(filter log_printfnoformat,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/log/log_printfnoformat -endif - -ifneq (,$(filter log_color,$(USEMODULE))) - USEMODULE_INCLUDES += $(RIOTBASE)/sys/log/log_color -endif diff --git a/sys/log_color/Kconfig b/sys/log_color/Kconfig new file mode 100644 index 0000000000..c5352a25e2 --- /dev/null +++ b/sys/log_color/Kconfig @@ -0,0 +1,16 @@ +# Copyright (c) 2019 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# +choice LOG +#the choice prompt is described in sys/Kconfig + +config MODULE_LOG_COLOR + bool "log_color: colored log output" + select MODULE_LOG + help + Implements a logging module with colored output. + +endchoice diff --git a/sys/log_color/Makefile b/sys/log_color/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/log_color/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/log_color/Makefile.include b/sys/log_color/Makefile.include new file mode 100644 index 0000000000..ed8997f511 --- /dev/null +++ b/sys/log_color/Makefile.include @@ -0,0 +1 @@ +USEMODULE_INCLUDES += $(RIOTBASE)/sys/log_color/include diff --git a/sys/log_color/include/log_module.h b/sys/log_color/include/log_module.h new file mode 100644 index 0000000000..0b035d2c67 --- /dev/null +++ b/sys/log_color/include/log_module.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2019 Inria + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_log_color log_color: Colored log module + * @ingroup sys + * @brief This module implements a logging module with colored output + * @{ + * + * @file + * @brief log_module header + * + * @author Alexandre Abadie + */ + +#ifndef LOG_MODULE_H +#define LOG_MODULE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * + * @brief log_write overridden function for colored output + * + * @param[in] level Logging level + * @param[in] format String format to print + */ +void log_write(unsigned level, const char *format, ...); + +#ifdef __cplusplus +} +#endif +#endif /* LOG_MODULE_H */ +/**@}*/ diff --git a/sys/log/log_color/log_module.h b/sys/log_color/log_color.c similarity index 74% rename from sys/log/log_color/log_module.h rename to sys/log_color/log_color.c index 82209c4459..7f522592b6 100644 --- a/sys/log/log_color/log_module.h +++ b/sys/log_color/log_color.c @@ -7,30 +7,22 @@ */ /** - * @defgroup sys_log_color Colored log module - * @ingroup sys - * @brief This module implements a logging module with colored output + * @addtogroup sys_log_color Colored log module * @{ * * @file - * @brief log_module header + * @brief log_color * * @author Alexandre Abadie */ -#ifndef LOG_MODULE_H -#define LOG_MODULE_H - #include #include #include +#include "kernel_defines.h" #include "log.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * @brief Default ANSI color escape code for error logs * @@ -72,11 +64,6 @@ extern "C" { */ #define LOG_RESET_ANSI_COLOR_CODE ("\033[0m") -/** - * @brief ANSI color escape codes array - * - * Internal use only - */ static const char * const _ansi_codes[] = { [LOG_ERROR] = LOG_ERROR_ANSI_COLOR_CODE, @@ -85,15 +72,9 @@ static const char * const _ansi_codes[] = [LOG_DEBUG] = LOG_DEBUG_ANSI_COLOR_CODE, }; -/** - * @brief log_write overridden function for colored output - * - * @param[in] level Logging level - * @param[in] format String format to print - */ -static inline void log_write(unsigned level, const char *format, ...) +void log_write(unsigned level, const char *format, ...) { - assert(level > 0); + assert((level > 0) && (level < ARRAY_SIZE(_ansi_codes))); printf("%s", _ansi_codes[level]); va_list args; @@ -110,14 +91,9 @@ static inline void log_write(unsigned level, const char *format, ...) va_end(args); printf(LOG_RESET_ANSI_COLOR_CODE); -#if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC) +#if !defined(__MSP430__) /* no fflush on msp430 */ fflush(stdout); #endif } - -#ifdef __cplusplus -} -#endif /**@}*/ -#endif /* LOG_MODULE_H */ diff --git a/sys/log_printfnoformat/Kconfig b/sys/log_printfnoformat/Kconfig new file mode 100644 index 0000000000..6993613c65 --- /dev/null +++ b/sys/log_printfnoformat/Kconfig @@ -0,0 +1,18 @@ +# Copyright (c) 2019 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# +choice LOG +#the choice prompt is described in sys/Kconfig + +config MODULE_LOG_PRINTFNOFORMAT + bool "log_printfnoformat: puts-based log" + select MODULE_LOG + help + Logging is implemented using puts instead of printf. Use it where printf + might be too heavy. This also serves as an example for logging + implementation. + +endchoice diff --git a/sys/log_printfnoformat/Makefile b/sys/log_printfnoformat/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/log_printfnoformat/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/log_printfnoformat/Makefile.include b/sys/log_printfnoformat/Makefile.include new file mode 100644 index 0000000000..23cb1560fc --- /dev/null +++ b/sys/log_printfnoformat/Makefile.include @@ -0,0 +1 @@ +USEMODULE_INCLUDES += $(RIOTBASE)/sys/log_printfnoformat/include diff --git a/sys/log/log_printfnoformat/log_module.h b/sys/log_printfnoformat/include/log_module.h similarity index 86% rename from sys/log/log_printfnoformat/log_module.h rename to sys/log_printfnoformat/include/log_module.h index 77cb88687d..b404d4a98d 100644 --- a/sys/log/log_printfnoformat/log_module.h +++ b/sys/log_printfnoformat/include/log_module.h @@ -7,9 +7,10 @@ */ /** - * @defgroup sys_log_printfnoformat puts log module + * @defgroup sys_log_printfnoformat log_printfnoformat: puts log module * @ingroup sys - * @brief This module implements an example logging module + * @brief This module implements an example logging module using puts to + * just print the format string saving on the number of libraries need * @{ * * @file