color log output on terminal

This commit is contained in:
Dustin Carlino 2018-09-23 14:22:25 -07:00
parent 09c3b017b9
commit de1033ac66
4 changed files with 12 additions and 2 deletions

View File

@ -27,3 +27,4 @@ sim = { path = "../sim" }
structopt = "0.2"
strum = "0.9.0"
strum_macros = "0.9.0"
yansi = "0.4.0"

View File

@ -1,5 +1,6 @@
// Call the log crate, but pre-set the target.
#[allow(unused_macros)]
macro_rules! debug {
( $( $x:expr ),* ) => {
{

View File

@ -29,6 +29,7 @@ extern crate structopt;
extern crate strum;
#[macro_use]
extern crate strum_macros;
extern crate yansi;
#[macro_use]
mod macros;

View File

@ -56,10 +56,17 @@ impl Log for LogAdapter {
}
fn log(&self, record: &Record) {
use yansi::Paint;
let line = format!(
"[{}] [{}] {}",
record.level(),
record.target(),
Paint::white(record.level()),
match record.target() {
"UI" => Paint::red("UI"),
"sim" => Paint::green("sim"),
"map" => Paint::blue("map"),
x => Paint::cyan(x),
},
record.args()
);
println!("{}", line);