15 stable releases (4 major)

4.0.1 Aug 27, 2018
4.0.0 Apr 7, 2018
3.3.0 Aug 18, 2017
3.2.0 Jul 20, 2016
0.0.1 Jan 18, 2015

#26 in Debugging

Download history 2794/week @ 2019-01-20 2195/week @ 2019-01-27 3937/week @ 2019-02-03 2601/week @ 2019-02-10 1847/week @ 2019-02-17 2148/week @ 2019-02-24 2173/week @ 2019-03-03 2190/week @ 2019-03-10 2649/week @ 2019-03-17 3126/week @ 2019-03-24 3016/week @ 2019-03-31 2552/week @ 2019-04-07 1745/week @ 2019-04-14 1486/week @ 2019-04-21 1650/week @ 2019-04-28

10,666 downloads per month
Used in 18 crates (14 directly)

MIT license

21KB
471 lines

Sending to Syslog in Rust

Build Status Coverage Status

A small library to write to local syslog.

Installation

syslog is available on crates.io and can be included in your Cargo enabled project like this:

[dependencies]
syslog = "^4.0"

documentation

Reference documentation is available here.

Example

extern crate syslog;

use syslog::{Facility, Formatter3164};

fn main() {
  let formatter = Formatter3164 {
    facility: Facility::LOG_USER,
    hostname: None,
    process: "myprogram".into(),
    pid: 42,
  };

  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");
    }
  }
}

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(formatter)
  • the tcp function takes an address for a remote TCP syslog server: tcp(formatter, "127.0.0.1:4242")
  • the udp function takes an address for a local port, and the address remote UDP syslog server: udp(formatter, "127.0.0.1:1234", "127.0.0.1:4242")

Dependencies

~1MB
~15K SLoC