From c7d52cbe2e8001d44f20327014db2be5d4bfe8fd Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Wed, 4 Mar 2026 10:08:31 +0100 Subject: [PATCH] feat: optionally set a different default Arduino stream To support the Arduino UNO Q it is important to avoid accessing the 'Serial' object from this library. This commit allows the user to set the default stream to something else, such as 'Serial1' or 'Serial2', by defining 'DEBUGLOG_DEFAULT_ARDUINO_STREAM' before including the library. This change is backward compatible, as the default will still be 'Serial' if the macro is not defined. Signed-off-by: Luca Burelli --- DebugLog/Manager.h | 2 +- DebugLog/Types.h | 4 ++++ README.md | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/DebugLog/Manager.h b/DebugLog/Manager.h index dfd8c9b..ad5953d 100644 --- a/DebugLog/Manager.h +++ b/DebugLog/Manager.h @@ -15,7 +15,7 @@ namespace debug { bool b_base_reset {true}; #ifdef ARDUINO - Stream* stream {&Serial}; + Stream* stream {&DEBUGLOG_DEFAULT_ARDUINO_STREAM}; FileLogger* logger {nullptr}; LogLevel file_lvl {DEBUGLOG_DEFAULT_FILE_LEVEL}; bool b_auto_save {false}; diff --git a/DebugLog/Types.h b/DebugLog/Types.h index 4d1c1ba..3649e45 100644 --- a/DebugLog/Types.h +++ b/DebugLog/Types.h @@ -132,4 +132,8 @@ namespace debug { #define DEBUGLOG_DEFAULT_FILE_LEVEL LogLevel::LVL_ERROR #endif +#ifndef DEBUGLOG_DEFAULT_ARDUINO_STREAM +#define DEBUGLOG_DEFAULT_ARDUINO_STREAM Serial +#endif + #endif // DEBUGLOG_TYPES_H diff --git a/README.md b/README.md index 0cfb01b..aef2386 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,13 @@ LOG_ATTACH_STREAM(your_tcp_client); LOG_ATTACH_STREAM(any_other_stream); ``` +The default can be changed by defining `DEBUGLOG_DEFAULT_ARDUINO_STREAM` before including `DebugLog.h`: + +```cpp +#define DEBUGLOG_DEFAULT_ARDUINO_STREAM Serial2 +#include +``` + ### Log Preamble Control The `LOG_PREAMBLE` macro is called every `LOG_XXXX`. It defines a string that will be printed between the `[LEVEL]` and your custom message. To override the default definition, you must define the macro **before** you `#include `