Merge pull request #412 from matthiasbeyer/libimagrt/color-log-output
Libimagrt/color log output
This commit is contained in:
commit
bd6c8ff3ff
3 changed files with 31 additions and 6 deletions
|
@ -10,6 +10,7 @@ log = "0.3"
|
|||
xdg-basedir = "0.2.2"
|
||||
itertools = "0.4"
|
||||
tempfile = "2.1.1"
|
||||
ansi_term = "0.7"
|
||||
|
||||
[dependencies.libimagstore]
|
||||
path = "../libimagstore"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#[macro_use] extern crate itertools;
|
||||
#[cfg(unix)] extern crate xdg_basedir;
|
||||
extern crate tempfile;
|
||||
extern crate ansi_term;
|
||||
|
||||
extern crate clap;
|
||||
extern crate toml;
|
||||
|
|
|
@ -24,14 +24,37 @@ impl Log for ImagLogger {
|
|||
}
|
||||
|
||||
fn log(&self, record: &LogRecord) {
|
||||
use ansi_term::Colour::Red;
|
||||
use ansi_term::Colour::Yellow;
|
||||
use ansi_term::Colour::Cyan;
|
||||
|
||||
if self.enabled(record.metadata()) {
|
||||
// TODO: This is just simple logging. Maybe we can enhance this lateron
|
||||
if record.metadata().level() == LogLevel::Debug {
|
||||
let loc = record.location();
|
||||
writeln!(stderr(), "[imag][{: <5}][{}][{: >5}]: {}",
|
||||
record.level(), loc.file(), loc.line(), record.args()).ok();
|
||||
} else {
|
||||
writeln!(stderr(), "[imag][{: <5}]: {}", record.level(), record.args()).ok();
|
||||
let loc = record.location();
|
||||
match record.metadata().level() {
|
||||
LogLevel::Debug => {
|
||||
let lvl = Cyan.paint(format!("{}", record.level()));
|
||||
let file = Cyan.paint(format!("{}", loc.file()));
|
||||
let ln = Cyan.paint(format!("{}", loc.line()));
|
||||
let args = Cyan.paint(format!("{}", record.args()));
|
||||
|
||||
writeln!(stderr(), "[imag][{: <5}][{}][{: >5}]: {}", lvl, file, ln, args).ok();
|
||||
},
|
||||
LogLevel::Warn | LogLevel::Error => {
|
||||
let lvl = Red.blink().paint(format!("{}", record.level()));
|
||||
let args = Red.paint(format!("{}", record.args()));
|
||||
|
||||
writeln!(stderr(), "[imag][{: <5}]: {}", lvl, args).ok();
|
||||
},
|
||||
LogLevel::Info => {
|
||||
let lvl = Yellow.paint(format!("{}", record.level()));
|
||||
let args = Yellow.paint(format!("{}", record.args()));
|
||||
|
||||
writeln!(stderr(), "[imag][{: <5}]: {}", lvl, args).ok();
|
||||
},
|
||||
_ => {
|
||||
writeln!(stderr(), "[imag][{: <5}]: {}", record.level(), record.args()).ok();
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue