about summary refs log blame commit diff stats
path: root/js/blotbotboot/repl.js
blob: 6ea6929335208e385c52c1a451a57423381c1e02 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                                         
// lifted from https://github.com/maryrosecook/littlelisp
var repl = require("repl");
var lisp = require("./lisp").lisp;

repl.start({
  prompt: "* ",
  eval: function (cmd, context, filename, callback) {
    var ret = lisp.interpret(lisp.parse(cmd));
    callback(null, ret);
  },
});
eral.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
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"));
    }
}