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.
This commit is contained in:
parent
327b9fd32e
commit
9a4cdc7e93
@ -23,22 +23,35 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
#include <stdio.h>
|
||||||
* @brief log_write overridden function
|
#include "esp_common_log.h"
|
||||||
*
|
|
||||||
* @param[in] level (unused)
|
|
||||||
* @param[in] format String that the function will print
|
|
||||||
*/
|
|
||||||
void log_write(unsigned level, const char *format, ...);
|
|
||||||
|
|
||||||
/**
|
#ifdef MODULE_LOG_PRINTFNOFORMAT
|
||||||
* @brief log_write overridden function, tagged version
|
|
||||||
*
|
static inline void log_write(unsigned level, const char *format, ...) {
|
||||||
* @param[in] level Level of the message
|
(void)level;
|
||||||
* @param[in] tag Additional information like function or module
|
puts(format);
|
||||||
* @param[in] format String that the function will print
|
}
|
||||||
*/
|
|
||||||
void log_write_tagged(unsigned level, const char *tag, const char *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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 <gunar@schorcht.net>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#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);
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user