Function syslog_tls::unix
source · pub fn unix<F: Clone>(formatter: F) -> Result<Logger<LoggerBackend, F>>
Expand description
Returns a Logger using unix socket to target local syslog ( using /dev/log or /var/run/syslog)
Examples found in repository?
examples/log.rs (line 17)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let formatter = Formatter3164 {
facility: Facility::LOG_USER,
hostname: None,
process: "myprogram".into(),
pid: 0,
};
let logger = syslog_tls::unix(formatter).expect("could not connect to syslog");
log::set_boxed_logger(Box::new(BasicLogger::new(logger)))
.map(|()| log::set_max_level(LevelFilter::Info))
.expect("could not register logger");
info!("hello world");
}
More examples
examples/write.rs (line 13)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
let formatter = Formatter3164 {
facility: Facility::LOG_USER,
hostname: None,
process: "myprogram".into(),
pid: 0,
};
match syslog_tls::unix(formatter) {
Err(e) => println!("impossible to connect to syslog: {:?}", e),
Ok(mut writer) => {
writer
.err("hello world")
.expect("could not write error message");
writer
.err("hello all".to_string())
.expect("could not write error message");
}
}
}
examples/rfc5424.rs (line 13)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() {
let formatter = Formatter5424 {
facility: Facility::LOG_USER,
hostname: None,
process: "myprogram".into(),
pid: 0,
};
match syslog_tls::unix(formatter) {
Err(e) => println!("impossible to connect to syslog: {:?}", e),
Ok(mut writer) => {
writer
.err(SyslogMessage {
message_level: 1,
structured: Vec::new(),
message: "hello world".to_string(),
})
.expect("could not write error message");
}
}
}