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:
toml
[dependencies]
syslog = "~3.1.0"
Reference documentation is available here.
```rust extern crate syslog;
use syslog::{Facility,Severity};
fn main() { match syslog::unix(Facility::LOGUSER) { Err(e) => println!("impossible to connect to syslog: {:?}", e), Ok(writer) => { let r = writer.send3164(Severity::LOGALERT, "hello world"); if r.iserr() { 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:
unix
function sends to the local syslog through a Unix socket: syslog::unix(Facility::LOG_USER)
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)
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)