From 26af2b2021c054d1bf4a4ae5df87a82d23415e96 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Sat, 9 Nov 2024 10:44:23 +0900 Subject: [PATCH 1/2] feat: support attach stream --- DebugLog.h | 1 + README.md | 21 ++++++++++++++++++++- examples/options/options.ino | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/DebugLog.h b/DebugLog.h index 5bbadab..90ec250 100644 --- a/DebugLog.h +++ b/DebugLog.h @@ -35,6 +35,7 @@ using DebugLogPrecision = arx::debug::LogPrecision; #ifdef ARDUINO #define LOG_ATTACH_SERIAL(s) DebugLog::Manager::get().attach(s) +#define LOG_ATTACH_STREAM(s) DebugLog::Manager::get().attach(s) // PRINT_FILE and PRINTLN_FILE are always enabled regardless of file_level // PRINT_FILE and PRINTLN_FILE do NOT print to Serial #define PRINT_FILE(...) DebugLog::Manager::get().print_file(__VA_ARGS__) diff --git a/README.md b/README.md index 6d8422c..0cfb01b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Logging library for Arduino that can output to both Serial and File with one lin ## Feature -- Output logs to `Serial` and `File` with one line at the same time +- Output logs to `Serial` (or any other `Stream`) and `File` with one line at the same time - Output logs with variadic arguments - Assertion support (suspend program with messages if assertion fails) - Release Mode `#define DEBUGLOG_DISABLE_LOG` can easily disable logging (`LOG_XXXX`, `ASSERT`) @@ -97,6 +97,24 @@ will output [TRACE] basic.ino L.30 setup : this is trace: log level 5 ``` +### Log Destination Control + +You can output the log to another `Serial` easily: + +```cpp +LOG_ATTACH_SERIAL(Serial2); +``` + +Also this library supports the log output to any `Stream` based instances. For example, you can change the log output destination to `Ethernet/WiFiClient`, `Ethernet/WiFiUDP` instead of default `Serial` as follows: + +```cpp +LOG_ATTACH_STREAM(your_udp_client); +// or +LOG_ATTACH_STREAM(your_tcp_client); +// or +LOG_ATTACH_STREAM(any_other_stream); +``` + ### 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 ` @@ -509,6 +527,7 @@ If you use `LOG_ATTACH_FS_MANUAL`, these macros are used to flush files manually #define LOG_SET_BASE_RESET(b) // Arduino Only #define LOG_ATTACH_SERIAL(serial) +#define LOG_ATTACH_STREAM(stream) #define LOG_FILE_IS_OPEN() #define LOG_FILE_GET_LEVEL() #define LOG_FILE_SET_LEVEL(lvl) diff --git a/examples/options/options.ino b/examples/options/options.ino index f423f47..ca7fcc1 100644 --- a/examples/options/options.ino +++ b/examples/options/options.ino @@ -13,6 +13,9 @@ void setup() { // You can change target stream (default: Serial) // LOG_ATTACH_SERIAL(Serial2); + // LOG_ATTACH_STREAM(udp_client); + // LOG_ATTACH_STREAM(tcp_client); + // LOG_ATTACH_STREAM(any_other_stream); // You can change auto reset for base setting (default: true) PRINTLN("You can print variable args with bases", From 98bef699af114f6f386a849be13ab39fbb57e814 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Sat, 9 Nov 2024 10:44:35 +0900 Subject: [PATCH 2/2] chore: bump version v0.8.4 --- library.json | 41 ++++++++++++++++++++--------------------- library.properties | 2 +- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/library.json b/library.json index 2118e94..89c8364 100644 --- a/library.json +++ b/library.json @@ -1,23 +1,22 @@ { - "name": "DebugLog", - "keywords": "assert, log, utility, serial", - "description": "Logging library for Arduino that can output to both Serial and File with one line", - "repository": { - "type": "git", - "url": "https://github.com/hideakitai/DebugLog.git" - }, - "authors": { - "name": "Hideaki Tai", - "url": "https://github.com/hideakitai", - "maintainer": true - }, - "version": "0.8.3", - "license": "MIT", - "frameworks": "*", - "platforms": "*", - "dependencies": - { - "hideakitai/ArxContainer": ">=0.6.0", - "hideakitai/ArxTypeTraits": "*" - } + "name": "DebugLog", + "keywords": "assert, log, utility, serial", + "description": "Logging library for Arduino that can output to both Serial and File with one line", + "repository": { + "type": "git", + "url": "https://github.com/hideakitai/DebugLog.git" + }, + "authors": { + "name": "Hideaki Tai", + "url": "https://github.com/hideakitai", + "maintainer": true + }, + "version": "0.8.4", + "license": "MIT", + "frameworks": "*", + "platforms": "*", + "dependencies": { + "hideakitai/ArxContainer": ">=0.6.0", + "hideakitai/ArxTypeTraits": "*" + } } diff --git a/library.properties b/library.properties index c4090b9..e0fc378 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=DebugLog -version=0.8.3 +version=0.8.4 author=hideakitai maintainer=hideakitai sentence=Logging library for Arduino that can output to both Serial and File with one line