Skip to content

Commit

Permalink
chore(examples): add syslog friendly format (#174)
Browse files Browse the repository at this point in the history
Closes #157
  • Loading branch information
Sven committed Jul 24, 2020
1 parent a5a7ddc commit b8c3754
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/syslog_friendly_format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::io::Write;

fn main() {
match std::env::var("RUST_LOG_STYLE") {
Ok(s) if s == "SYSTEMD" => env_logger::builder()
.format(|buf, record| {
writeln!(
buf,
"<{}>{}: {}",
match record.level() {
log::Level::Error => 3,
log::Level::Warn => 4,
log::Level::Info => 6,
log::Level::Debug => 7,
log::Level::Trace => 7,
},
record.target(),
record.args()
)
})
.init(),
_ => env_logger::init(),
};
}

0 comments on commit b8c3754

Please sign in to comment.