Skip to content

Commit b581f7d

Browse files
authored
Merge pull request #25 from hideakitai/feature/support-attach-stream
Feature/support attach stream
2 parents c54587e + 98bef69 commit b581f7d

5 files changed

Lines changed: 45 additions & 23 deletions

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",

library.json

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
{
2-
"name": "DebugLog",
3-
"keywords": "assert, log, utility, serial",
4-
"description": "Logging library for Arduino that can output to both Serial and File with one line",
5-
"repository": {
6-
"type": "git",
7-
"url": "https://github.com/hideakitai/DebugLog.git"
8-
},
9-
"authors": {
10-
"name": "Hideaki Tai",
11-
"url": "https://github.com/hideakitai",
12-
"maintainer": true
13-
},
14-
"version": "0.8.3",
15-
"license": "MIT",
16-
"frameworks": "*",
17-
"platforms": "*",
18-
"dependencies":
19-
{
20-
"hideakitai/ArxContainer": ">=0.6.0",
21-
"hideakitai/ArxTypeTraits": "*"
22-
}
2+
"name": "DebugLog",
3+
"keywords": "assert, log, utility, serial",
4+
"description": "Logging library for Arduino that can output to both Serial and File with one line",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/hideakitai/DebugLog.git"
8+
},
9+
"authors": {
10+
"name": "Hideaki Tai",
11+
"url": "https://github.com/hideakitai",
12+
"maintainer": true
13+
},
14+
"version": "0.8.4",
15+
"license": "MIT",
16+
"frameworks": "*",
17+
"platforms": "*",
18+
"dependencies": {
19+
"hideakitai/ArxContainer": ">=0.6.0",
20+
"hideakitai/ArxTypeTraits": "*"
21+
}
2322
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DebugLog
2-
version=0.8.3
2+
version=0.8.4
33
author=hideakitai
44
maintainer=hideakitai
55
sentence=Logging library for Arduino that can output to both Serial and File with one line

0 commit comments

Comments
 (0)