Skip to content

Commit 4807b8c

Browse files
committedNov 20, 2023
Version 0.1.5
1 parent b4ba5fa commit 4807b8c

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed
 

‎Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "breadcrumbs"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
edition = "2021"
55
authors = ["Michael Reeves <linux479@duck.com>"]
66
license = "Apache-2.0"

‎README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Breadcrumbs is a beautiful, tiny traceback and logging library for Rust that off
1414
Add the following to your `Cargo.toml`:
1515
```toml
1616
[dependencies]
17-
breadcrumbs = "0.1.4"
17+
breadcrumbs = "0.1.5"
1818
```
1919

2020
Then, initalize `breadcrumbs` once in your `main.rs` or `lib.rs`:
@@ -34,6 +34,10 @@ impl LogListener for MyLogListener {
3434
fn on_log(&mut self, log: Log) {
3535
if log.level.is_at_least(LogLevel::Warn) {
3636
println!("{}", log);
37+
} else {
38+
// 💡 New in 0.1.5 - Remove unnecessary logs to save memory
39+
// Useful in embedded usecases
40+
log.remove();
3741
}
3842
}
3943
}

‎src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ impl Log {
116116
message,
117117
}
118118
}
119+
/// Removes the log from the stored traceback of logs.
120+
/// This log will not use up memory or be printed by the traceback macros.
121+
/// Useful in embedded systems where memory is limited.
122+
///
123+
/// # Example Usecase
124+
/// ```rust
125+
/// use breadcrumbs::{LogListener, Log};
126+
///
127+
/// struct MyLogListener;
128+
/// impl LogListener for MyLogListener {
129+
/// fn on_log(&mut self, log: Log) {
130+
/// if !log.level.is_at_least(breadcrumbs::LogLevel::Warn) {
131+
/// log.remove();
132+
/// }
133+
/// }
134+
/// }
135+
/// ```
136+
pub fn remove(&self) {
137+
let mut logs = LOGS.lock();
138+
let index = logs.iter().position(|log| log == self).unwrap();
139+
logs.remove(index);
140+
}
119141
}
120142

121143
/// A trait for handling log entries.

0 commit comments

Comments
 (0)
Please sign in to comment.