about summary refs log tree commit diff stats
path: root/html/archive
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-15 20:35:43 -0700
committerKartik Agaram <vc@akkartik.com>2021-06-15 20:38:53 -0700
commitb28899fe3792f7cef535d49f0db5ab8a759b5db2 (patch)
treee1278878f17c7e8fd614b5b50d86bd8b9b428f15 /html/archive
parent03e6248c14216bd71af0f0db0e311713ca5fbf72 (diff)
downloadmu-b28899fe3792f7cef535d49f0db5ab8a759b5db2.tar.gz
.
Support newlines. Looks like we pasted the input from the browser window
during the pairing session.
Diffstat (limited to 'html/archive')
0 files changed, 0 insertions, 0 deletions
f='#n32'>32 33 34 35 36 37 38 39 40
41
42
43
44
45
46
47
48







































                                                                                             
                                                      


                                  
                                                                     


                                                      
use std::fs;
use std::fs::File;

use chrono::offset::Utc;
use simplelog::*;

pub const FILE: &str = "/tmp/clinte.log";

pub fn init() {
    // If the log file exists on startup,
    // move and timestamp it so we get a
    // fresh log file.
    if fs::metadata(FILE).is_ok() {
        let mut newpath = FILE.to_string();
        let time = Utc::now().to_rfc3339();
        newpath.push_str(".");
        newpath.push_str(&time);
        fs::rename(FILE, newpath).unwrap();
    }

    CombinedLogger::init(vec![
        TermLogger::new(LevelFilter::Warn, Config::default(), TerminalMode::Stderr).unwrap(),
        WriteLogger::new(
            LevelFilter::Info,
            Config::default(),
            File::create(FILE).unwrap(),
        ),
    ])
    .expect("Unable to initialize logging");
}

#[cfg(test)]
mod tests {
    use super::*;

    use log::info;

    #[test]
    fn init_logs() {
        let blank = " ".bytes().collect::<Vec<u8>>();
        fs::write("/tmp/clinte.log", &blank).unwrap();
        init();

        info!("TEST LOG MESSAGE");
        let logfile = fs::read_to_string("/tmp/clinte.log").unwrap();
        assert!(logfile.contains("TEST LOG MESSAGE"));
    }
}