From c0a25e08c0a618525ee9258a8fe6761b34a63e83 Mon Sep 17 00:00:00 2001 From: "matt.baker" Date: Fri, 16 Aug 2024 12:57:53 +0100 Subject: [PATCH 1/2] Add build flag to disable line end defines ARDUINOLOG_DISABLE_LINE_END_DEFINES Fixes #2 --- src/ArduinoLog.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ArduinoLog.h b/src/ArduinoLog.h index 9622f75..b62d77d 100644 --- a/src/ArduinoLog.h +++ b/src/ArduinoLog.h @@ -63,9 +63,25 @@ typedef void (*printfunction)(Print*, int); #define LOG_COLOR_WHITE "\033[;37m" #define LOG_COLOR_BLACK "\033[;38;5;240m" #define LOG_COLOR_END "\033[0m" + +#ifndef ARDUINOLOG_DISABLE_LINE_END_DEFINES +#ifndef CR #define CR "\n" +#else +#warning "CR already defined" +#endif +#ifndef LF #define LF "\r" +#else +#warning "LF already defined" +#endif +#ifndef NL #define NL "\n\r" +#else +#warning "NL already defined" +#endif +#endif + #define LOGGING_VERSION 1_0_4 /** From a7078ff76fb61875d712e1a76318f458d20313b9 Mon Sep 17 00:00:00 2001 From: "matt.baker" Date: Fri, 16 Aug 2024 17:55:18 +0100 Subject: [PATCH 2/2] Replace reference to CR with Logging::lineEnd constant This overcomes problems if ARDUINOLOG_DISABLE_LINE_END_DEFINES is defined. --- src/ArduinoLog.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ArduinoLog.h b/src/ArduinoLog.h index b62d77d..f937d20 100644 --- a/src/ArduinoLog.h +++ b/src/ArduinoLog.h @@ -123,6 +123,8 @@ typedef void (*printfunction)(Print*, int); class Logging { public: + static constexpr char lineEnd[] = "\n"; + explicit Logging(); /** @@ -390,7 +392,7 @@ class Logging { void printFormat(const char format, va_list *args); - template void printLevel(int level, bool cr, T msg, ...) { + template void printLevel(int level, bool newLine, T msg, ...) { #ifndef DISABLE_LOGGING if (level > _level) { return; @@ -444,8 +446,8 @@ class Logging { } } - if (cr) { - writeLog(CR); + if (newLine) { + writeLog(lineEnd); } if (_showColors) {