diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-15 17:47:01 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-05-15 17:47:01 +0200 |
commit | f22624302c5ab9abb6d88d75825d04ea0ca7a6b4 (patch) | |
tree | b036ce826ec45dd8e0b4cb6a95b91a38c1fdf92e /libimagutil | |
parent | 5dd0fa900c1a3495ffd72f0dc017b2dfaaa895b3 (diff) |
Make trace() output red
Diffstat (limited to 'libimagutil')
-rw-r--r-- | libimagutil/src/trace.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/libimagutil/src/trace.rs b/libimagutil/src/trace.rs index 3a66bcb8..e04b292f 100644 --- a/libimagutil/src/trace.rs +++ b/libimagutil/src/trace.rs @@ -2,6 +2,8 @@ use std::error::Error; use std::io::Write; use std::io::stderr; +use ansi_term::Colour::Red; + /// Print an Error type and its cause recursively /// /// The error is printed with "Error NNNN :" as prefix, where "NNNN" is a number which increases @@ -29,8 +31,9 @@ pub fn trace_error(e: &Error) { /// Output is the same as for `trace_error()`, though there are only `max` levels printed. pub fn trace_error_maxdepth(e: &Error, max: u64) { let n = count_error_causes(e); - write!(stderr(), - "{}/{} Levels of errors will be printed\n", (if max > n { n } else { max }), n).ok(); + let msg = Red.blink().paint(format!("{}/{} Levels of errors will be printed\n", + (if max > n { n } else { max }), n)); + write!(stderr(), "{}", msg).ok(); print_trace_maxdepth(n, e, max); write!(stderr(), "").ok(); } @@ -55,7 +58,7 @@ fn print_trace_maxdepth(idx: u64, e: &Error, max: u64) -> Option<&Error> { } else { write!(stderr(), "\n").ok(); } - write!(stderr(), "ERROR[{:>4}]: {}", idx, e.description()).ok(); + write!(stderr(), "{}: {}", Red.paint(format!("ERROR[{:>4}]", idx)), e.description()).ok(); e.cause() } @@ -65,7 +68,7 @@ fn count_error_causes(e: &Error) -> u64 { } fn print_trace_dbg(idx: u64, e: &Error) { - debug!("ERROR[{:>4}]: {}", idx, e.description()); + debug!("{}: {}", Red.blink().paint(format!("ERROR[{:>4}]", idx)), e.description()); if e.cause().is_some() { print_trace_dbg(idx + 1, e.cause().unwrap()); } |