Color log output
Color as follows: * Debug output -> Cyan * Warning, errors -> Red, with the type (WARN; ERROR) red blinking * All other output yellow.
This commit is contained in:
parent
344296487d
commit
376a23b8ce
1 changed files with 29 additions and 6 deletions
|
@ -24,14 +24,37 @@ impl Log for ImagLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log(&self, record: &LogRecord) {
|
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()) {
|
if self.enabled(record.metadata()) {
|
||||||
// TODO: This is just simple logging. Maybe we can enhance this lateron
|
// TODO: This is just simple logging. Maybe we can enhance this lateron
|
||||||
if record.metadata().level() == LogLevel::Debug {
|
let loc = record.location();
|
||||||
let loc = record.location();
|
match record.metadata().level() {
|
||||||
writeln!(stderr(), "[imag][{: <5}][{}][{: >5}]: {}",
|
LogLevel::Debug => {
|
||||||
record.level(), loc.file(), loc.line(), record.args()).ok();
|
let lvl = Cyan.paint(format!("{}", record.level()));
|
||||||
} else {
|
let file = Cyan.paint(format!("{}", loc.file()));
|
||||||
writeln!(stderr(), "[imag][{: <5}]: {}", record.level(), record.args()).ok();
|
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