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

#8 in Unix APIs

Download history 2544/week @ 2018-10-11 2658/week @ 2018-10-18 2200/week @ 2018-10-25 2690/week @ 2018-11-01 2452/week @ 2018-11-08 2579/week @ 2018-11-15 2071/week @ 2018-11-22 1866/week @ 2018-11-29 1989/week @ 2018-12-06 2340/week @ 2018-12-13 2319/week @ 2018-12-20 1545/week @ 2018-12-27 1295/week @ 2019-01-03

8,029 downloads per month
Used in 16 crates (13 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