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)
9fn main() {
10 let formatter = Formatter3164 {
11 facility: Facility::LOG_USER,
12 hostname: None,
13 process: "myprogram".into(),
14 pid: 0,
15 };
16
17 let logger = syslog_tls::unix(formatter).expect("could not connect to syslog");
18 log::set_boxed_logger(Box::new(BasicLogger::new(logger)))
19 .map(|()| log::set_max_level(LevelFilter::Info))
20 .expect("could not register logger");
21
22 info!("hello world");
23}
More examples
examples/write.rs (line 13)
5fn main() {
6 let formatter = Formatter3164 {
7 facility: Facility::LOG_USER,
8 hostname: None,
9 process: "myprogram".into(),
10 pid: 0,
11 };
12
13 match syslog_tls::unix(formatter) {
14 Err(e) => println!("impossible to connect to syslog: {:?}", e),
15 Ok(mut writer) => {
16 writer
17 .err("hello world")
18 .expect("could not write error message");
19 writer
20 .err("hello all".to_string())
21 .expect("could not write error message");
22 }
23 }
24}
examples/rfc5424.rs (line 13)
5fn main() {
6 let formatter = Formatter5424 {
7 facility: Facility::LOG_USER,
8 hostname: None,
9 process: "myprogram".into(),
10 pid: 0,
11 };
12
13 match syslog_tls::unix(formatter) {
14 Err(e) => println!("impossible to connect to syslog: {:?}", e),
15 Ok(mut writer) => {
16 writer
17 .err(SyslogMessage {
18 message_level: 1,
19 structured: Vec::new(),
20 message: "hello world".to_string(),
21 })
22 .expect("could not write error message");
23 }
24 }
25}