-
Notifications
You must be signed in to change notification settings - Fork 51
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
Capture logs inside tests? #54
Comments
It seems something like this will work. If there's no simpler way could I suggest this be added to the examples? fn install_test_logger() {
// This'll fail if called twice; don't worry.
let _ = fern::Dispatch::new()
// ...
.level(log::LevelFilter::Debug)
.chain(fern::Output::call(|record| println!("{}", record.args())))
.apply();
}``` |
Thanks! I hadn't realized that the test framework's hook was per-thread rather than global. Makes sense now that I think about it, though. Adding that as an example sounds like a good idea. It might also be worth adding to this note as well (or we could just remove the stdout from this example; it isn't really relevant): Lines 691 to 701 in 6666bd2
|
Hi,
It would be great if tests could be written to the tests's stdout, and then (by default) shown only if the test fails.
It looks like
.chain(std::io::stdout())
sends them to the process's real stdout, bypassing the test framework's hooks. I see there's a lot of history on this in rust-lang/rust#42474 and perhaps it's not possible for Fern to fix? But it seems like ifprintln!
is captured, at least Fern could simply doprintln!
for everything.Or perhaps this is possible already and I'm just missing it, and if so perhaps it could be clearer in the docs?
The text was updated successfully, but these errors were encountered: