Skip to content
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
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ license-file = "LICENSE"

[dependencies]
log = "0.4.0"
regex = "1.11.2"
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,33 @@ See the [documentation](https://docs.rs/logcap/latest/logcap).
### Capture logs within a thread

```rust
use logcap::CaptureScope;
use log::info;
use log::{info, Level};
use logcap::assert_logs;

#[test]
fn test_logs() {
logcap::setup();

// test logic outputting logs
info!("foobar");
info!("moocow");
info!("hello, world!");

// make assertions on logs
logcap::consume(|logs| {
assert_eq!(1, logs.len());
assert_eq!("foobar", logs[0].body);
});
assert_logs!(
"foobar",
"^m.*w$",
(Level::Info, "hello, world!")
);
}
```

### Capture logs across threads
Run tests with `--test_threads=1` to avoid clobbering logs between tests, or use a mutex for synchronization.

```rust
use logcap::CaptureScope;
use log::{LevelFilter,warn};
use logcap::{assert_logs, CaptureScope};

#[test]
fn test_logs() {
Expand Down
Loading