ceethane 0.1.0

A logging crate designed to make it easy to inject and pass contextual information to log lines
Documentation
use std::collections::HashMap;
use std::os::unix::net::UnixDatagram;
use serde_json::Value;
use ::Level;
use ::backend::Backend;

#[derive(Debug, Clone)]
pub struct CeeSyslog {
    destination: String
}

impl CeeSyslog {
    pub fn new(destination: String) -> CeeSyslog {
        CeeSyslog {
            destination: destination
        }
    }
}

impl Backend for CeeSyslog {
    fn send(&mut self, name: &String, level: Level, pairs: &HashMap<String, Value>) {
        let stream = match UnixDatagram::unbound() {
            Ok(s) => s,
            Err(e) => {
                println!("{:?}", e);
                return
            },
        };

        match stream.set_nonblocking(true) {
            Ok(_) => true,
            Err(_) => return,
        };

        let frame = super::to_cee_frame(name, level, pairs);
        match stream.send_to(&frame.as_bytes(), &self.destination) {
            Ok(_) => true,
            Err(_) => return,
        };
    }
}