Skip to main content

file/
file.rs

1//! Writing logs to a file and stdout at the same time.
2//!
3//! ANSI colours stay on stdout but are stripped from the file.
4//!
5//! Run with: `cargo run --example file`
6//! Then inspect: `cat app.log`
7
8use tiny_tracing::{Logger, Output, info, warn};
9
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    Logger::new()
12        .with_output(Output::Both("app.log".into()))
13        .init()?;
14
15    info!("this line goes to both stdout and app.log");
16    warn!(file = "app.log", "check the file for a colour-free copy");
17    Ok(())
18}