diff --git a/src/DebugConfiguration.h b/src/DebugConfiguration.h index f7733d5b1..d82ea186c 100644 --- a/src/DebugConfiguration.h +++ b/src/DebugConfiguration.h @@ -29,10 +29,10 @@ #define LOG_ERROR(...) SEGGER_RTT_printf(0, __VA_ARGS__) #else #ifdef DEBUG_PORT -#define LOG_DEBUG(...) DEBUG_PORT.logDebug(__VA_ARGS__) -#define LOG_INFO(...) DEBUG_PORT.logDebug(__VA_ARGS__) -#define LOG_WARN(...) DEBUG_PORT.logDebug(__VA_ARGS__) -#define LOG_ERROR(...) DEBUG_PORT.logDebug(__VA_ARGS__) +#define LOG_DEBUG(...) DEBUG_PORT.log(LOG_LEVEL_DEBUG, __VA_ARGS__) +#define LOG_INFO(...) DEBUG_PORT.log(LOG_LEVEL_INFO, __VA_ARGS__) +#define LOG_WARN(...) DEBUG_PORT.log(LOG_LEVEL_WARN, __VA_ARGS__) +#define LOG_ERROR(...) DEBUG_PORT.log(LOG_LEVEL_ERROR, __VA_ARGS__) #else #define LOG_DEBUG(...) #define LOG_INFO(...) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 66c83171a..e7f305e19 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -58,7 +58,7 @@ size_t RedirectablePrint::vprintf(const char *format, va_list arg) return len; } -size_t RedirectablePrint::logDebug(const char *format, ...) +size_t RedirectablePrint::log(const char *logLevel, const char *format, ...) { size_t r = 0; @@ -86,9 +86,9 @@ size_t RedirectablePrint::logDebug(const char *format, ...) int min = (hms % SEC_PER_HOUR) / SEC_PER_MIN; int sec = (hms % SEC_PER_HOUR) % SEC_PER_MIN; // or hms % SEC_PER_MIN - r += printf("%02d:%02d:%02d %u ", hour, min, sec, millis() / 1000); + r += printf("%s | %02d:%02d:%02d %u ", logLevel, hour, min, sec, millis() / 1000); } else - r += printf("??:??:?? %u ", millis() / 1000); + r += printf("%s | ??:??:?? %u ", logLevel, millis() / 1000); auto thread = concurrency::OSThread::currentThread; if (thread) { @@ -99,7 +99,6 @@ size_t RedirectablePrint::logDebug(const char *format, ...) print("] "); } } - r += vprintf(format, arg); va_end(arg); diff --git a/src/RedirectablePrint.h b/src/RedirectablePrint.h index 9443d1672..8fabd4a72 100644 --- a/src/RedirectablePrint.h +++ b/src/RedirectablePrint.h @@ -34,7 +34,7 @@ class RedirectablePrint : public Print * log message. Otherwise we assume more prints will come before the log message ends. This * allows you to call logDebug a few times to build up a single log message line if you wish. */ - size_t logDebug(const char * format, ...) __attribute__ ((format (printf, 2, 3))); + size_t log(const char *logLevel, const char *format, ...) __attribute__ ((format (printf, 3, 4))); /** like printf but va_list based */ size_t vprintf(const char *format, va_list arg);