Skip to content

Commit 3cd1c18

Browse files
committed
refactor: Addapt syslog example to auto-detection
1 parent 8da6eb4 commit 3cd1c18

2 files changed

Lines changed: 11 additions & 23 deletions

File tree

examples/syslog_friendly_format.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
use std::io::Write;
2-
31
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-
};
2+
env_logger::builder()
3+
.parse_default_env()
4+
// While journald-logging is auto-detected, you can manually override it.
5+
// Especially useful if you are using a different logging system.
6+
//.format_syslog(true)
7+
.init();
8+
9+
// Prints in a human readable way if run interactively,
10+
// and in a syslog-compatible way if run as a systemd service.
11+
log::info!("we are logging");
2412
}

src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<T: Display> Display for StyledValue<T> {
274274
#[cfg(not(feature = "color"))]
275275
type StyledValue<T> = T;
276276

277-
struct SyslogFormatter;
277+
pub(crate) struct SyslogFormatter;
278278

279279
impl SyslogFormatter {
280280
pub(crate) fn build(&mut self) -> FormatFn {

0 commit comments

Comments
 (0)