flexi_syslog

Crates.ioflexi_syslog
lib.rsflexi_syslog
version0.5.3
sourcesrc
created_at2021-12-19 22:40:00.738054
updated_at2024-03-03 21:45:31.830853
descriptionA syslog writer for flexi_logger
homepagehttps://crates.io/crates/flexi_syslog
repositoryhttps://github.com/bheylin/flexi_syslog
max_upload_size
id500526
size51,427
Brian Heylin (bheylin)

documentation

https://docs.rs/flexi_syslog

README

Flexi-Syslog

docs crates build status

A flexi-logger LogWriter that formats and transports log records to the syslog using the syslog crate.

[dependencies]
flexi_logger = "0.24"
flexi_syslog = "0.5"
syslog = "6.0"

Example Usage

fn main() {
    // syslog's Formatter5424 does not implement the rfc5424 timestamp correctly
    let formatter = flexi_syslog::Formatter5424 {
        facility: syslog::Facility::LOG_USER,
        hostname: None,
        process: "basic".into(),
        pid: 0,
    };

    let sys_logger = syslog::unix(formatter).expect("Failed to init unix socket");

    let syslog_writer = flexi_syslog::log_writer::Builder::default()
        .max_log_level(log::LevelFilter::Info)
        .build(sys_logger);

    let logger = flexi_logger::Logger::try_with_str("info")
        .expect("Failed to init logger")
        .log_to_writer(Box::new(syslog_writer));

    let handle = logger.start().expect("Failed to start logger");

    log::info!("Info gets through");
    log::trace!("Trace is filtered");

    handle.flush();
}
Commit count: 46

cargo fmt