Last active
November 18, 2020 21:57
-
-
Save neoneye/75c9d358af5e70e06870dbbf09507e0e to your computer and use it in GitHub Desktop.
Print out filename:linenumber when logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::Write; | |
std::env::set_var("RUST_LOG", "debug"); | |
env_logger::builder() | |
.format(|buf, record| { | |
writeln!(buf, "{} - {}:{} - {}", record.level(), record.file().unwrap_or("N/A"), record.line().unwrap_or(0), record.args()) | |
}) | |
.init(); | |
trace!("some trace log"); | |
debug!("some debug log"); | |
info!("some information log"); | |
warn!("some warning log"); | |
error!("some error log"); | |
// Output looks like this: | |
// DEBUG - src/main.rs:13 - some debug log | |
// INFO - src/main.rs:14 - some information log | |
// WARN - src/main.rs:15 - some warning log | |
// ERROR - src/main.rs:16 - some error log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment