Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support attach stream #25

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading