Expand description
Syslog
This crate provides facilities to send log messages via syslog. It supports Unix sockets for local syslog, UDP and TCP for remote servers.
Messages can be passed directly without modification, or in RFC 3164 or RFC 5424 format
The code is available on GitLab
§Example
use syslog_too::{Facility, Formatter3164};
let formatter = Formatter3164 {
facility: Facility::LOG_USER,
hostname: None,
process: "myprogram".into(),
pid: 0,
};
match syslog::unix(formatter) {
Err(e) => println!("impossible to connect to syslog: {:?}", e),
Ok(mut writer) => {
writer.err("hello world").expect("could not write error message");
}
}It can be used directly with the log crate as follows:
extern crate log;
use syslog_too::{Facility, Formatter3164, Logger3164};
use log::{SetLoggerError, LevelFilter, info};
let formatter = Formatter3164 {
facility: Facility::LOG_USER,
hostname: None,
process: "myprogram".into(),
pid: 0,
};
let logger = match syslog_too::unix(formatter) {
Err(e) => { println!("impossible to connect to syslog: {:?}", e); return; },
Ok(logger) => logger,
};
log::set_boxed_logger(Box::new(Logger3164::new(logger)))
.map(|()| log::set_max_level(LevelFilter::Info));
info!("hello world");Structs§
- Formatter3164
- Formatter5424
- Logger
- Generic main logging structure
- Logger3164
- Logger struct for the RFC 3164 BSD syslog protocol.
- Logger5424
- Logger struct for the RFC 5424 syslog protocol.
Enums§
Traits§
Functions§
- init
- Initializes logging subsystem for log crate
- init_
tcp - TCP Logger init function compatible with log crate
- init_
udp - UDP Logger init function compatible with log crate
- init_
unix - Unix socket Logger init function compatible with log crate
- init_
unix_ custom - Unix socket Logger init function compatible with log crate and user provided socket path
- tcp
- returns a TCP logger connecting
localandserver - udp
- returns a UDP logger connecting
localandserver - unix
- Returns a Logger using unix socket to target local syslog ( using /dev/log or /var/run/syslog)
- unix_
custom - Returns a Logger using unix socket to target local syslog at user provided path