Skip to content

Commit b8c3754

Browse files
author
Sven
authored
chore(examples): add syslog friendly format (#174)
Closes #157
1 parent a5a7ddc commit b8c3754

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/syslog_friendly_format.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::io::Write;
2+
3+
fn main() {
4+
match std::env::var("RUST_LOG_STYLE") {
5+
Ok(s) if s == "SYSTEMD" => env_logger::builder()
6+
.format(|buf, record| {
7+
writeln!(
8+
buf,
9+
"<{}>{}: {}",
10+
match record.level() {
11+
log::Level::Error => 3,
12+
log::Level::Warn => 4,
13+
log::Level::Info => 6,
14+
log::Level::Debug => 7,
15+
log::Level::Trace => 7,
16+
},
17+
record.target(),
18+
record.args()
19+
)
20+
})
21+
.init(),
22+
_ => env_logger::init(),
23+
};
24+
}

0 commit comments

Comments
 (0)