From f5f0eca46fa7a8510fe38ba842e3de962d6a0cfc Mon Sep 17 00:00:00 2001 From: John Date: Tue, 11 Jan 2022 09:30:57 -0500 Subject: [PATCH 1/3] Namespace log level defines --- ArduinoLog.cpp | 2 +- ArduinoLog.h | 78 +++++++++---------- README.md | 18 ++--- examples/Log-advanced/Log-advanced.ino | 2 +- examples/Log-basic/Log-basic.ino | 4 +- examples/platformio-basic/src/main.cpp | 6 +- .../platformio-basic/test/test_native.cpp | 2 +- keywords.txt | 16 ++-- 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/ArduinoLog.cpp b/ArduinoLog.cpp index 538ea3d..9d3cacb 100644 --- a/ArduinoLog.cpp +++ b/ArduinoLog.cpp @@ -43,7 +43,7 @@ void Logging::begin(int level, Print* logOutput, bool showLevel) void Logging::setLevel(int level) { #ifndef DISABLE_LOGGING - _level = constrain(level, LOG_LEVEL_SILENT, LOG_LEVEL_VERBOSE); + _level = constrain(level, ARDUINO_LOG_LOG_LEVEL_SILENT, ARDUINO_LOG_LOG_LEVEL_VERBOSE); #endif } diff --git a/ArduinoLog.h b/ArduinoLog.h index 9ec9fb0..f1f264f 100644 --- a/ArduinoLog.h +++ b/ArduinoLog.h @@ -37,14 +37,14 @@ typedef void (*printfunction)(Print*, int); // ************************************************************************ //#define DISABLE_LOGGING -#define LOG_LEVEL_SILENT 0 -#define LOG_LEVEL_FATAL 1 -#define LOG_LEVEL_ERROR 2 -#define LOG_LEVEL_WARNING 3 -#define LOG_LEVEL_INFO 4 -#define LOG_LEVEL_NOTICE 4 -#define LOG_LEVEL_TRACE 5 -#define LOG_LEVEL_VERBOSE 6 +#define ARDUINO_LOG_LOG_LEVEL_SILENT 0 +#define ARDUINO_LOG_LOG_LEVEL_FATAL 1 +#define ARDUINO_LOG_LOG_LEVEL_ERROR 2 +#define ARDUINO_LOG_LOG_LEVEL_WARNING 3 +#define ARDUINO_LOG_LOG_LEVEL_INFO 4 +#define ARDUINO_LOG_LOG_LEVEL_NOTICE 4 +#define ARDUINO_LOG_LOG_LEVEL_TRACE 5 +#define ARDUINO_LOG_LOG_LEVEL_VERBOSE 6 #define CR "\n" #define LF "\r" @@ -78,14 +78,14 @@ typedef void (*printfunction)(Print*, int); * * ---- Loglevels * - * 0 - LOG_LEVEL_SILENT no output - * 1 - LOG_LEVEL_FATAL fatal errors - * 2 - LOG_LEVEL_ERROR all errors - * 3 - LOG_LEVEL_WARNING errors and warnings - * 4 - LOG_LEVEL_INFO errors, warnings and notices - * 4 - LOG_LEVEL_NOTICE Same as INFO, kept for backward compatibility - * 5 - LOG_LEVEL_TRACE errors, warnings, notices, traces - * 6 - LOG_LEVEL_VERBOSE all + * 0 - ARDUINO_LOG_LOG_LEVEL_SILENT no output + * 1 - ARDUINO_LOG_LOG_LEVEL_FATAL fatal errors + * 2 - ARDUINO_LOG_LOG_LEVEL_ERROR all errors + * 3 - ARDUINO_LOG_LOG_LEVEL_WARNING errors and warnings + * 4 - ARDUINO_LOG_LOG_LEVEL_INFO errors, warnings and notices + * 4 - ARDUINO_LOG_LOG_LEVEL_NOTICE Same as INFO, kept for backward compatibility + * 5 - ARDUINO_LOG_LOG_LEVEL_TRACE errors, warnings, notices, traces + * 6 - ARDUINO_LOG_LOG_LEVEL_VERBOSE all */ class Logging @@ -96,7 +96,7 @@ class Logging */ Logging() #ifndef DISABLE_LOGGING - : _level(LOG_LEVEL_SILENT), + : _level(ARDUINO_LOG_LOG_LEVEL_SILENT), _showLevel(true), _logOutput(NULL) #endif @@ -182,7 +182,7 @@ class Logging * Output a fatal error message. Output message contains * F: followed by original message * Fatal error messages are printed out at - * loglevels >= LOG_LEVEL_FATAL + * loglevels >= ARDUINO_LOG_LOG_LEVEL_FATAL * * \param msg format string to output * \param ... any number of variables @@ -190,13 +190,13 @@ class Logging */ template void fatal(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_FATAL, false, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_FATAL, false, msg, args...); #endif } template void fatalln(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_FATAL, true, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_FATAL, true, msg, args...); #endif } @@ -204,7 +204,7 @@ class Logging * Output an error message. Output message contains * E: followed by original message * Error messages are printed out at - * loglevels >= LOG_LEVEL_ERROR + * loglevels >= ARDUINO_LOG_LOG_LEVEL_ERROR * * \param msg format string to output * \param ... any number of variables @@ -212,20 +212,20 @@ class Logging */ template void error(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_ERROR, false, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_ERROR, false, msg, args...); #endif } template void errorln(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_ERROR, true, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_ERROR, true, msg, args...); #endif } /** * Output a warning message. Output message contains * W: followed by original message * Warning messages are printed out at - * loglevels >= LOG_LEVEL_WARNING + * loglevels >= ARDUINO_LOG_LOG_LEVEL_WARNING * * \param msg format string to output * \param ... any number of variables @@ -233,13 +233,13 @@ class Logging */ template void warning(T msg, Args...args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_WARNING, false, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_WARNING, false, msg, args...); #endif } template void warningln(T msg, Args...args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_WARNING, true, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_WARNING, true, msg, args...); #endif } @@ -247,7 +247,7 @@ class Logging * Output a notice message. Output message contains * N: followed by original message * Notice messages are printed out at - * loglevels >= LOG_LEVEL_NOTICE + * loglevels >= ARDUINO_LOG_LOG_LEVEL_NOTICE * * \param msg format string to output * \param ... any number of variables @@ -255,25 +255,25 @@ class Logging */ template void notice(T msg, Args...args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_NOTICE, false, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_NOTICE, false, msg, args...); #endif } template void noticeln(T msg, Args...args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_NOTICE, true, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_NOTICE, true, msg, args...); #endif } template void info(T msg, Args...args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_INFO, false, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_INFO, false, msg, args...); #endif } template void infoln(T msg, Args...args) { #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_INFO, true, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_INFO, true, msg, args...); #endif } @@ -281,7 +281,7 @@ class Logging * Output a trace message. Output message contains * N: followed by original message * Trace messages are printed out at - * loglevels >= LOG_LEVEL_TRACE + * loglevels >= ARDUINO_LOG_LOG_LEVEL_TRACE * * \param msg format string to output * \param ... any number of variables @@ -289,13 +289,13 @@ class Logging */ template void trace(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_TRACE, false, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_TRACE, false, msg, args...); #endif } template void traceln(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_TRACE, true, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_TRACE, true, msg, args...); #endif } @@ -303,7 +303,7 @@ class Logging * Output a verbose message. Output message contains * V: followed by original message * Debug messages are printed out at - * loglevels >= LOG_LEVEL_VERBOSE + * loglevels >= ARDUINO_LOG_LOG_LEVEL_VERBOSE * * \param msg format string to output * \param ... any number of variables @@ -311,13 +311,13 @@ class Logging */ template void verbose(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_VERBOSE, false, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_VERBOSE, false, msg, args...); #endif } template void verboseln(T msg, Args... args){ #ifndef DISABLE_LOGGING - printLevel(LOG_LEVEL_VERBOSE, true, msg, args...); + printLevel(ARDUINO_LOG_LOG_LEVEL_VERBOSE, true, msg, args...); #endif } @@ -342,9 +342,9 @@ class Logging { return; } - if (level < LOG_LEVEL_SILENT) + if (level < ARDUINO_LOG_LOG_LEVEL_SILENT) { - level = LOG_LEVEL_SILENT; + level = ARDUINO_LOG_LOG_LEVEL_SILENT; } diff --git a/README.md b/README.md index 628cd76..cee322a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ This package has been published to the Arduino & PlatformIO package managers, bu Serial.begin(9600); // Initialize with log level and log output. - Log.begin (LOG_LEVEL_VERBOSE, &Serial); + Log.begin (ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial); // Start logging text and formatted values Log.errorln ( "Log as Error with binary values : %b, %B" , 23 , 345808); @@ -68,19 +68,19 @@ begin(int level, Print* logOutput) The loglevels available are ``` -* 0 - LOG_LEVEL_SILENT no output -* 1 - LOG_LEVEL_FATAL fatal errors -* 2 - LOG_LEVEL_ERROR all errors -* 3 - LOG_LEVEL_WARNING errors, and warnings -* 4 - LOG_LEVEL_NOTICE errors, warnings and notices -* 5 - LOG_LEVEL_TRACE errors, warnings, notices & traces -* 6 - LOG_LEVEL_VERBOSE all +* 0 - ARDUINO_LOG_LOG_LEVEL_SILENT no output +* 1 - ARDUINO_LOG_LOG_LEVEL_FATAL fatal errors +* 2 - ARDUINO_LOG_LOG_LEVEL_ERROR all errors +* 3 - ARDUINO_LOG_LOG_LEVEL_WARNING errors, and warnings +* 4 - ARDUINO_LOG_LOG_LEVEL_NOTICE errors, warnings and notices +* 5 - ARDUINO_LOG_LOG_LEVEL_TRACE errors, warnings, notices & traces +* 6 - ARDUINO_LOG_LOG_LEVEL_VERBOSE all ``` example ``` -Log.begin(LOG_LEVEL_ERROR, &Serial, true); +Log.begin(ARDUINO_LOG_LOG_LEVEL_ERROR, &Serial, true); ``` if you want to fully remove all logging code, uncomment `#define DISABLE_LOGGING` in `ArduinoLog.h`, this may significantly reduce your sketch/library size. diff --git a/examples/Log-advanced/Log-advanced.ino b/examples/Log-advanced/Log-advanced.ino index 2d0c867..b8a3595 100644 --- a/examples/Log-advanced/Log-advanced.ino +++ b/examples/Log-advanced/Log-advanced.ino @@ -26,7 +26,7 @@ void setup() { Log.setPrefix(printPrefix); // set prefix similar to NLog Log.setSuffix(printSuffix); // set suffix - Log.begin(LOG_LEVEL_VERBOSE, &Serial); + Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial); Log.setShowLevel(false); // Do not show loglevel, we will do this in the prefix } diff --git a/examples/Log-basic/Log-basic.ino b/examples/Log-basic/Log-basic.ino index 181292b..f37b22c 100644 --- a/examples/Log-basic/Log-basic.ino +++ b/examples/Log-basic/Log-basic.ino @@ -29,11 +29,11 @@ void setup() { randomSeed(analogRead(0)); // Pass log level, whether to show log level, and print interface. // Available levels are: - // LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE + // ARDUINO_LOG_LOG_LEVEL_SILENT, ARDUINO_LOG_LOG_LEVEL_FATAL, ARDUINO_LOG_LOG_LEVEL_ERROR, ARDUINO_LOG_LOG_LEVEL_WARNING, ARDUINO_LOG_LOG_LEVEL_INFO, ARDUINO_LOG_LOG_LEVEL_TRACE, ARDUINO_LOG_LOG_LEVEL_VERBOSE // Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h // this will significantly reduce your project size - Log.begin(LOG_LEVEL_VERBOSE, &Serial); + Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial); //Start logging diff --git a/examples/platformio-basic/src/main.cpp b/examples/platformio-basic/src/main.cpp index 0a87923..7f9601f 100644 --- a/examples/platformio-basic/src/main.cpp +++ b/examples/platformio-basic/src/main.cpp @@ -39,13 +39,13 @@ void setup() { randomSeed(analogRead(0)); // Pass log level, whether to show log level, and print interface. // Available levels are: - // LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, - // LOG_LEVEL_NOTICE, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE Note: if you want to + // ARDUINO_LOG_LOG_LEVEL_SILENT, ARDUINO_LOG_LOG_LEVEL_FATAL, ARDUINO_LOG_LOG_LEVEL_ERROR, ARDUINO_LOG_LOG_LEVEL_WARNING, + // ARDUINO_LOG_LOG_LEVEL_NOTICE, ARDUINO_LOG_LOG_LEVEL_TRACE, ARDUINO_LOG_LOG_LEVEL_VERBOSE Note: if you want to // fully remove all logging code, uncomment #define DISABLE_LOGGING in // Logging.h // this will significantly reduce your project size - Log.begin(LOG_LEVEL_VERBOSE, &Serial); + Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial); // Start logging diff --git a/examples/platformio-basic/test/test_native.cpp b/examples/platformio-basic/test/test_native.cpp index ce46efe..8f2e167 100644 --- a/examples/platformio-basic/test/test_native.cpp +++ b/examples/platformio-basic/test/test_native.cpp @@ -121,7 +121,7 @@ void set_up_logging_captures() { void setUp(void) { ArduinoFakeReset(); - Log.begin(LOG_LEVEL_VERBOSE, &Serial); + Log.begin(ARDUINO_LOG_LOG_LEVEL_VERBOSE, &Serial); set_up_logging_captures(); } void test_int_values() { diff --git a/keywords.txt b/keywords.txt index 9204507..d1f8f0f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -47,12 +47,12 @@ Log KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### -LOG_LEVEL_SILENT LITERAL1 Constants -LOG_LEVEL_FATAL LITERAL1 Constants -LOG_LEVEL_ERROR LITERAL1 Constants -LOG_LEVEL_WARNING LITERAL1 Constants -LOG_LEVEL_NOTICE LITERAL1 Constants -LOG_LEVEL_INFO LITERAL1 Constants -LOG_LEVEL_TRACE LITERAL1 Constants -LOG_LEVEL_VERBOSE LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_SILENT LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_FATAL LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_ERROR LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_WARNING LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_NOTICE LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_INFO LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_TRACE LITERAL1 Constants +ARDUINO_LOG_LOG_LEVEL_VERBOSE LITERAL1 Constants From c29bfc7984795bc5bbb563c6ea584843b7ddb884 Mon Sep 17 00:00:00 2001 From: ldenisey <39246034+ldenisey@users.noreply.github.com> Date: Sun, 15 Jan 2023 15:31:45 +0100 Subject: [PATCH 2/3] Fix CR LF definition CR and LF definition were inverted --- ArduinoLog.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ArduinoLog.h b/ArduinoLog.h index 9ec9fb0..3f91fd8 100644 --- a/ArduinoLog.h +++ b/ArduinoLog.h @@ -46,9 +46,9 @@ typedef void (*printfunction)(Print*, int); #define LOG_LEVEL_TRACE 5 #define LOG_LEVEL_VERBOSE 6 -#define CR "\n" -#define LF "\r" -#define NL "\n\r" +#define CR "\r" +#define LF "\n" +#define NL "\r\n" #define LOGGING_VERSION 1_0_4 /** From 57d350a25428376935b793a2138210320cf3801c Mon Sep 17 00:00:00 2001 From: Gavin Hurlbut Date: Tue, 24 Jan 2023 12:01:05 -0500 Subject: [PATCH 3/3] Removed "register" as it is obsolete after C++11 --- ArduinoLog.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ArduinoLog.cpp b/ArduinoLog.cpp index 538ea3d..804fcb9 100644 --- a/ArduinoLog.cpp +++ b/ArduinoLog.cpp @@ -172,12 +172,12 @@ void Logging::printFormat(const char format, va_list *args) { } else if (format == 's') { - register char *s = va_arg(*args, char *); + char *s = va_arg(*args, char *); _logOutput->print(s); } else if (format == 'S') { - register __FlashStringHelper *s = va_arg(*args, __FlashStringHelper *); + __FlashStringHelper *s = va_arg(*args, __FlashStringHelper *); _logOutput->print(s); } else if (format == 'd' || format == 'i') @@ -196,7 +196,7 @@ void Logging::printFormat(const char format, va_list *args) { { _logOutput->print("0x"); //_logOutput->print(va_arg(*args, int), HEX); - register uint16_t h = (uint16_t) va_arg( *args, int ); + uint16_t h = (uint16_t) va_arg( *args, int ); if (h<0xFFF) _logOutput->print('0'); if (h<0xFF ) _logOutput->print('0'); if (h<0xF ) _logOutput->print('0'); @@ -204,7 +204,7 @@ void Logging::printFormat(const char format, va_list *args) { } else if (format == 'p') { - register Printable *obj = (Printable *) va_arg(*args, int); + Printable *obj = (Printable *) va_arg(*args, int); _logOutput->print(*obj); } else if (format == 'b') @@ -229,7 +229,7 @@ void Logging::printFormat(const char format, va_list *args) { _logOutput->print((char) va_arg(*args, int)); } else if( format == 'C' ) { - register char c = (char) va_arg( *args, int ); + char c = (char) va_arg( *args, int ); if (c>=0x20 && c<0x7F) { _logOutput->print(c); } else {