ImagLogger: Add option to not include file/line in dbg logging
This commit is contained in:
parent
2c4946a82c
commit
22741d71c0
1 changed files with 14 additions and 3 deletions
|
@ -28,6 +28,7 @@ use ansi_term::ANSIString;
|
||||||
|
|
||||||
pub struct ImagLogger {
|
pub struct ImagLogger {
|
||||||
prefix: String,
|
prefix: String,
|
||||||
|
dbg_fileline: bool,
|
||||||
lvl: LogLevel,
|
lvl: LogLevel,
|
||||||
color_enabled: bool,
|
color_enabled: bool,
|
||||||
}
|
}
|
||||||
|
@ -37,11 +38,17 @@ impl ImagLogger {
|
||||||
pub fn new(lvl: LogLevel) -> ImagLogger {
|
pub fn new(lvl: LogLevel) -> ImagLogger {
|
||||||
ImagLogger {
|
ImagLogger {
|
||||||
prefix: "[imag]".to_owned(),
|
prefix: "[imag]".to_owned(),
|
||||||
|
dbg_fileline: true,
|
||||||
lvl: lvl,
|
lvl: lvl,
|
||||||
color_enabled: true
|
color_enabled: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_dbg_file_and_line(mut self, b: bool) -> ImagLogger {
|
||||||
|
self.dbg_fileline = b;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_prefix(mut self, pref: String) -> ImagLogger {
|
pub fn with_prefix(mut self, pref: String) -> ImagLogger {
|
||||||
self.prefix = pref;
|
self.prefix = pref;
|
||||||
self
|
self
|
||||||
|
@ -87,11 +94,15 @@ impl Log for ImagLogger {
|
||||||
match record.metadata().level() {
|
match record.metadata().level() {
|
||||||
LogLevel::Debug => {
|
LogLevel::Debug => {
|
||||||
let lvl = self.color_or_not(Cyan, format!("{}", record.level()));
|
let lvl = self.color_or_not(Cyan, format!("{}", record.level()));
|
||||||
|
let args = self.color_or_not(Cyan, format!("{}", record.args()));
|
||||||
|
if self.dbg_fileline {
|
||||||
let file = self.color_or_not(Cyan, format!("{}", loc.file()));
|
let file = self.color_or_not(Cyan, format!("{}", loc.file()));
|
||||||
let ln = self.color_or_not(Cyan, format!("{}", loc.line()));
|
let ln = self.color_or_not(Cyan, format!("{}", loc.line()));
|
||||||
let args = self.color_or_not(Cyan, format!("{}", record.args()));
|
|
||||||
|
|
||||||
writeln!(stderr(), "{}[{: <5}][{}][{: >5}]: {}", self.prefix, lvl, file, ln, args).ok();
|
writeln!(stderr(), "{}[{: <5}][{}][{: >5}]: {}", self.prefix, lvl, file, ln, args).ok();
|
||||||
|
} else {
|
||||||
|
writeln!(stderr(), "{}[{: <5}]: {}", self.prefix, lvl, args).ok();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
LogLevel::Warn | LogLevel::Error => {
|
LogLevel::Warn | LogLevel::Error => {
|
||||||
let lvl = self.style_or_not(Red.blink(), format!("{}", record.level()));
|
let lvl = self.style_or_not(Red.blink(), format!("{}", record.level()));
|
||||||
|
|
Loading…
Reference in a new issue