summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-01-22 13:30:41 +0100
committerGitHub <noreply@github.com>2017-01-22 13:30:41 +0100
commit9d7a26ba3ac42aa89670d032c97e5500ebde0828 (patch)
tree193f6d89d93386783990973649c129051d366e59
parent2c4946a82c8eca33b619aeffc8a264566278658f (diff)
parent22741d71c0e4d60bd27849bdc634cc8f3fe42fc0 (diff)
downloadimag-9d7a26ba3ac42aa89670d032c97e5500ebde0828.zip
imag-9d7a26ba3ac42aa89670d032c97e5500ebde0828.tar.gz
Merge pull request #856 from matthiasbeyer/libimagrt/dbg-fileline-opt
ImagLogger: Add option to not include file/line in dbg logging
-rw-r--r--libimagrt/src/logger.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/libimagrt/src/logger.rs b/libimagrt/src/logger.rs
index 9881aa0..d0efc82 100644
--- a/libimagrt/src/logger.rs
+++ b/libimagrt/src/logger.rs
@@ -28,6 +28,7 @@ use ansi_term::ANSIString;
pub struct ImagLogger {
prefix: String,
+ dbg_fileline: bool,
lvl: LogLevel,
color_enabled: bool,
}
@@ -37,11 +38,17 @@ impl ImagLogger {
pub fn new(lvl: LogLevel) -> ImagLogger {
ImagLogger {
prefix: "[imag]".to_owned(),
+ dbg_fileline: true,
lvl: lvl,
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 {
self.prefix = pref;
self
@@ -87,11 +94,15 @@ impl Log for ImagLogger {
match record.metadata().level() {
LogLevel::Debug => {
let lvl = self.color_or_not(Cyan, format!("{}", record.level()));
- let file = self.color_or_not(Cyan, format!("{}", loc.file()));
- 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();
+ if self.dbg_fileline {
+ let file = self.color_or_not(Cyan, format!("{}", loc.file()));
+ let ln = self.color_or_not(Cyan, format!("{}", loc.line()));
+
+ writeln!(stderr(), "{}[{: <5}][{}][{: >5}]: {}", self.prefix, lvl, file, ln, args).ok();
+ } else {
+ writeln!(stderr(), "{}[{: <5}]: {}", self.prefix, lvl, args).ok();
+ }
},
LogLevel::Warn | LogLevel::Error => {
let lvl = self.style_or_not(Red.blink(), format!("{}", record.level()));