From 9a4cdc7e93b9d38540486d1a057c36318f07c7b0 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 20 Aug 2019 16:23:42 +0200 Subject: [PATCH] cpu/esp32: log_module implementation The implementation of `log_module` for ESP32 was changed from functions to a macro-based implementation to be able to use the bunch of macros for colored and tagget log output generation. --- cpu/esp32/include/log_module.h | 43 +++++++++------ cpu/esp32/log_module.c | 99 ---------------------------------- 2 files changed, 28 insertions(+), 114 deletions(-) delete mode 100644 cpu/esp32/log_module.c diff --git a/cpu/esp32/include/log_module.h b/cpu/esp32/include/log_module.h index 60229f7134..7f5bf2e083 100644 --- a/cpu/esp32/include/log_module.h +++ b/cpu/esp32/include/log_module.h @@ -23,22 +23,35 @@ extern "C" { #endif -/** - * @brief log_write overridden function - * - * @param[in] level (unused) - * @param[in] format String that the function will print - */ -void log_write(unsigned level, const char *format, ...); +#include +#include "esp_common_log.h" -/** - * @brief log_write overridden function, tagged version - * - * @param[in] level Level of the message - * @param[in] tag Additional information like function or module - * @param[in] format String that the function will print - */ -void log_write_tagged(unsigned level, const char *tag, const char *format, ...); +#ifdef MODULE_LOG_PRINTFNOFORMAT + +static inline void log_write(unsigned level, const char *format, ...) { + (void)level; + puts(format); +} + +#else /* MODULE_LOG_PRINTFNOFORMAT */ + +#define log_write(level, ...) \ + do { \ + if (level == LOG_ERROR) { \ + LOG_TAG(LOG_ERROR, E, __func__, ##__VA_ARGS__); \ + } \ + else if (level == LOG_WARNING) { \ + LOG_TAG(LOG_WARNING, W, __func__, ##__VA_ARGS__); \ + } \ + else if (level == LOG_INFO) { \ + LOG_TAG(LOG_INFO, D, __func__, ##__VA_ARGS__); \ + } \ + else if (level == LOG_DEBUG) { \ + LOG_TAG(LOG_DEBUG, E, __func__, ##__VA_ARGS__); \ + } \ + } while (0U); + +#endif /* MODULE_LOG_PRINTFNOFORMAT */ #ifdef __cplusplus } diff --git a/cpu/esp32/log_module.c b/cpu/esp32/log_module.c deleted file mode 100644 index b90b26850f..0000000000 --- a/cpu/esp32/log_module.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2018 Gunar Schorcht - * - * 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. - */ - -/** - * @ingroup cpu_esp32 - * @{ - * - * @file - * @brief Log module to realize consistent log messages - * - * @author Gunar Schorcht - */ - -#include -#include - -#include "rom/ets_sys.h" - -#include "cpu_conf.h" -#include "log.h" -#include "syscalls.h" - -char _printf_buf[PRINTF_BUFSIZ]; -bool _new_line = true; - -void log_write(unsigned level, const char *format, ...) -{ - if (level == LOG_NONE) { - return; - } - - if (_new_line) { - /* if we are in new line, we print the prefix */ - char lc = 'U'; - switch (level) { - case LOG_ERROR : lc = 'E'; break; - case LOG_WARNING: lc = 'W'; break; - case LOG_INFO : lc = 'I'; break; - case LOG_DEBUG : lc = 'D'; break; - case LOG_ALL : lc = 'V'; break; - } - ets_printf("%c (%u) ", lc, system_get_time_ms()); - } - - va_list arglist; - va_start(arglist, format); - - int ret = vsnprintf(_printf_buf, PRINTF_BUFSIZ, format, arglist); - - if (ret > 0) { - ets_printf (_printf_buf); - } - - va_end(arglist); - - _new_line = (strrchr(format, '\n') != NULL); -} - -void log_write_tagged(unsigned level, const char *tag, const char *format, ...) -{ - if (level == LOG_NONE) { - return; - } - - if (_new_line) { - /* if we are in new line, we print the prefix */ - char lc = 'U'; - switch (level) { - case LOG_ERROR : lc = 'E'; break; - case LOG_WARNING: lc = 'W'; break; - case LOG_INFO : lc = 'I'; break; - case LOG_DEBUG : lc = 'D'; break; - case LOG_ALL : lc = 'V'; break; - } - #if LOG_TAG_IN_BRACKETS - ets_printf("%c (%u) [%10s]: ", lc, system_get_time_ms(), tag); - #else - ets_printf("%c (%u) %10s: ", lc, system_get_time_ms(), tag); - #endif - } - - va_list arglist; - va_start(arglist, format); - - int ret = vsnprintf(_printf_buf, PRINTF_BUFSIZ, format, arglist); - - if (ret > 0) { - ets_printf (_printf_buf); - } - - va_end(arglist); - - _new_line = (strrchr(format, '\n') != NULL); -}