Skip to content

Commit 26af2b2

Browse files
committed
feat: support attach stream
1 parent c54587e commit 26af2b2

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

DebugLog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using DebugLogPrecision = arx::debug::LogPrecision;
3535

3636
#ifdef ARDUINO
3737
#define LOG_ATTACH_SERIAL(s) DebugLog::Manager::get().attach(s)
38+
#define LOG_ATTACH_STREAM(s) DebugLog::Manager::get().attach(s)
3839
// PRINT_FILE and PRINTLN_FILE are always enabled regardless of file_level
3940
// PRINT_FILE and PRINTLN_FILE do NOT print to Serial
4041
#define PRINT_FILE(...) DebugLog::Manager::get().print_file(__VA_ARGS__)

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Logging library for Arduino that can output to both Serial and File with one lin
1111
1212
## Feature
1313

14-
- Output logs to `Serial` and `File` with one line at the same time
14+
- Output logs to `Serial` (or any other `Stream`) and `File` with one line at the same time
1515
- Output logs with variadic arguments
1616
- Assertion support (suspend program with messages if assertion fails)
1717
- Release Mode `#define DEBUGLOG_DISABLE_LOG` can easily disable logging (`LOG_XXXX`, `ASSERT`)
@@ -97,6 +97,24 @@ will output
9797
[TRACE] basic.ino L.30 setup : this is trace: log level 5
9898
```
9999

100+
### Log Destination Control
101+
102+
You can output the log to another `Serial` easily:
103+
104+
```cpp
105+
LOG_ATTACH_SERIAL(Serial2);
106+
```
107+
108+
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:
109+
110+
```cpp
111+
LOG_ATTACH_STREAM(your_udp_client);
112+
// or
113+
LOG_ATTACH_STREAM(your_tcp_client);
114+
// or
115+
LOG_ATTACH_STREAM(any_other_stream);
116+
```
117+
100118
### Log Preamble Control
101119

102120
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 <DebugLog.h>`
@@ -509,6 +527,7 @@ If you use `LOG_ATTACH_FS_MANUAL`, these macros are used to flush files manually
509527
#define LOG_SET_BASE_RESET(b)
510528
// Arduino Only
511529
#define LOG_ATTACH_SERIAL(serial)
530+
#define LOG_ATTACH_STREAM(stream)
512531
#define LOG_FILE_IS_OPEN()
513532
#define LOG_FILE_GET_LEVEL()
514533
#define LOG_FILE_SET_LEVEL(lvl)

examples/options/options.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ void setup() {
1313

1414
// You can change target stream (default: Serial)
1515
// LOG_ATTACH_SERIAL(Serial2);
16+
// LOG_ATTACH_STREAM(udp_client);
17+
// LOG_ATTACH_STREAM(tcp_client);
18+
// LOG_ATTACH_STREAM(any_other_stream);
1619

1720
// You can change auto reset for base setting (default: true)
1821
PRINTLN("You can print variable args with bases",

0 commit comments

Comments
 (0)