output_redirection/
output_redirection.rs

1use hackerlog::*;
2use std::fs::File;
3
4fn main() -> std::io::Result<()> {
5    // First log to stdout
6    info!("This goes to terminal");
7
8    // Redirect to a file
9    let log_file = File::create("test.log")?;
10    logger().set_writer(Box::new(log_file))?;
11
12    info!("This goes to test.log");
13    warn!("This warning also goes to test.log");
14
15    Ok(())
16}