summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-01-21 12:51:59 +0100
committerGitHub <noreply@github.com>2017-01-21 12:51:59 +0100
commitc96e129b40c34a0fd99df3a9bf32285337885a4a (patch)
tree5490760fac48ec1f3315bd03c1295b945e213ed3
parent0cf564091ece3c12ab83b1c5bb8555b1149c3d21 (diff)
parentddf811a589f8489b75e94b58ee40274e8766ba99 (diff)
downloadimag-c96e129b40c34a0fd99df3a9bf32285337885a4a.zip
imag-c96e129b40c34a0fd99df3a9bf32285337885a4a.tar.gz
Merge pull request #853 from matthiasbeyer/libimagrt/logger-pub
Make logger types public
-rw-r--r--libimagrt/src/lib.rs2
-rw-r--r--libimagrt/src/logger.rs15
2 files changed, 12 insertions, 5 deletions
diff --git a/libimagrt/src/lib.rs b/libimagrt/src/lib.rs
index 13c004b..8255661 100644
--- a/libimagrt/src/lib.rs
+++ b/libimagrt/src/lib.rs
@@ -49,9 +49,9 @@ extern crate libimagutil;
#[macro_use] extern crate libimagerror;
mod configuration;
-mod logger;
pub mod error;
+pub mod logger;
pub mod runtime;
pub mod setup;
diff --git a/libimagrt/src/logger.rs b/libimagrt/src/logger.rs
index 2e6244f..9881aa0 100644
--- a/libimagrt/src/logger.rs
+++ b/libimagrt/src/logger.rs
@@ -27,6 +27,7 @@ use ansi_term::Colour;
use ansi_term::ANSIString;
pub struct ImagLogger {
+ prefix: String,
lvl: LogLevel,
color_enabled: bool,
}
@@ -35,11 +36,17 @@ impl ImagLogger {
pub fn new(lvl: LogLevel) -> ImagLogger {
ImagLogger {
+ prefix: "[imag]".to_owned(),
lvl: lvl,
color_enabled: true
}
}
+ pub fn with_prefix(mut self, pref: String) -> ImagLogger {
+ self.prefix = pref;
+ self
+ }
+
pub fn with_color(mut self, b: bool) -> ImagLogger {
self.color_enabled = b;
self
@@ -84,22 +91,22 @@ impl Log for ImagLogger {
let ln = self.color_or_not(Cyan, format!("{}", loc.line()));
let args = self.color_or_not(Cyan, format!("{}", record.args()));
- writeln!(stderr(), "[imag][{: <5}][{}][{: >5}]: {}", lvl, file, ln, args).ok();
+ writeln!(stderr(), "{}[{: <5}][{}][{: >5}]: {}", self.prefix, lvl, file, ln, args).ok();
},
LogLevel::Warn | LogLevel::Error => {
let lvl = self.style_or_not(Red.blink(), format!("{}", record.level()));
let args = self.color_or_not(Red, format!("{}", record.args()));
- writeln!(stderr(), "[imag][{: <5}]: {}", lvl, args).ok();
+ writeln!(stderr(), "{}[{: <5}]: {}", self.prefix, lvl, args).ok();
},
LogLevel::Info => {
let lvl = self.color_or_not(Yellow, format!("{}", record.level()));
let args = self.color_or_not(Yellow, format!("{}", record.args()));
- writeln!(stderr(), "[imag][{: <5}]: {}", lvl, args).ok();
+ writeln!(stderr(), "{}[{: <5}]: {}", self.prefix, lvl, args).ok();
},
_ => {
- writeln!(stderr(), "[imag][{: <5}]: {}", record.level(), record.args()).ok();
+ writeln!(stderr(), "{}[{: <5}]: {}", self.prefix, record.level(), record.args()).ok();
},
}
}