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

#4 in Unix APIs

Download history 1644/week @ 2018-06-04 1834/week @ 2018-06-11 2410/week @ 2018-06-18 1723/week @ 2018-06-25 2077/week @ 2018-07-02 2491/week @ 2018-07-09 2243/week @ 2018-07-16 2089/week @ 2018-07-23 1937/week @ 2018-07-30 1870/week @ 2018-08-06 1201/week @ 2018-08-13 1402/week @ 2018-08-20 1167/week @ 2018-08-27

8,029 downloads per month
Used in 16 crates (11 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
~12K SLoC