<commit_before>//
// Copyright (c) 2016, <NAME> <<EMAIL>>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

extern crate syslog;
use logger::syslog::{Facility, Severity};

pub struct Logger {

    name:    &'static str,
    version: &'static str
}

impl Logger {
    /*
    pub fn start(&self) {
        //self.name = &NAME;
        //self.version = VERSION.to_string();
        
        //self.name = "MountAndExec";
        //
        //TODO
        //
        //return;
    }
    */
    pub fn new(n: &'static str,
               v: &'static str) -> Logger {

        match syslog::unix(Facility::LOG_USER) {
            Err(e)     => println!("impossible to connect to syslog: {:?}", e),
            Ok(writer) => {
                let r = writer.send(Severity::LOG_ALERT, "hello world");
                if r.is_err() {
                    println!("error sending the log {}", r.err().expect("got error"));
                }
            }
        }


        
        //
        //TODO make writer
        //
        Logger{name: n, version: v}
    }
}<commit_msg>add syslog wrapper<commit_after>//
// Copyright (c) 2016, <NAME> <<EMAIL>>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

extern crate syslog;
use self::syslog::{Facility, Severity};
use self::syslog::unix;
use std::io;

pub struct Logger {
    writer: Box<syslog::Logger>
}

impl Logger {
    pub fn new(name: &str) -> Logger {
        let res = unix(Facility::LOG_USER);
        if res.is_ok() {
            let mut w = res.unwrap();
            w.set_process_name(name.to_string());
            return Logger{writer: w};
        }
        panic!("Impossible to connect to syslog!");
    }

    pub fn info(&self, s: &str) {
        let res = self.writer.send_3164(Severity::LOG_INFO, s);
        if res.is_err() {
            self.to_console(res);
        }
    }

    pub fn error(&self, s: &str) {
        let res = self.writer.send_3164(Severity::LOG_ERR, s);
        if res.is_err() {
            self.to_console(res);
        }
    }

    fn to_console(&self, r: Result<usize, io::Error>) {
        println!("Impossible to write to syslog: {:?}", r);
    }
}
{'fraction_non_alphanumeric': 0.1502442996742671, 'fraction_numerical': 0.009771986970684038, 'mean_word_length': 1.860302677532014, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '292886', 'n_tokens_mistral': 824, 'n_tokens_neox': 794, 'n_words': 224}