Skip to content

Commit

Permalink
Merge pull request #25 from hideakitai/feature/support-attach-stream
Browse files Browse the repository at this point in the history
Feature/support attach stream
  • Loading branch information
hideakitai authored Nov 9, 2024
2 parents c54587e + 98bef69 commit b581f7d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
1 change: 1 addition & 0 deletions DebugLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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 <DebugLog.h>`
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions examples/options/options.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 20 additions & 21 deletions library.json
Original file line number Diff line number Diff line change
@@ -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": "*"
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b581f7d

Please sign in to comment.