A small library to write to local syslog.
syslog is available on crates.io and can be included in your Cargo enabled project like this:
[dependencies]
syslog = "~3.3.0"
Reference documentation is available here.
extern crate syslog;
use syslog::{Facility,Severity};
fn main() {
match syslog::unix(Facility::LOG_USER) {
Err(e) => println!("impossible to connect to syslog: {:?}", e),
Ok(writer) => {
let r = writer.send_3164(Severity::LOG_ALERT, "hello world");
if r.is_err() {
println!("error sending the log {}", r.err().expect("got error"));
}
}
}
}
The struct syslog::Logger
implements Log
from the log
crate, so it can be used as backend for other logging systems.
There are 3 functions to create loggers:
- the
unix
function sends to the local syslog through a Unix socket:syslog::unix(Facility::LOG_USER)
- the
tcp
function takes an address for a remote TCP syslog server and a hostname:tcp("127.0.0.1:4242", "localhost".to_string(), Facility::LOG_USER)
- the
udp
function takes an address for a local port, and the address remote UDP syslog server and a hostname:udp("127.0.0.1:1234", "127.0.0.1:4242", "localhost".to_string(), Facility::LOG_USER)