From 40d727a01c106955fa8fb693f75f08732279752d Mon Sep 17 00:00:00 2001 From: eupn <36292692+eupn@users.noreply.github.com> Date: Fri, 2 Nov 2018 18:13:12 +0300 Subject: [PATCH] fix: more readable timestamp format for logging (#1912) * Use more readable timestamp format for logging * Add logging level highlighting * Change date and time format to YYYYMMDD from MM-DD --- util/src/logger.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/util/src/logger.rs b/util/src/logger.rs index 3cb65c328..99847849b 100644 --- a/util/src/logger.rs +++ b/util/src/logger.rs @@ -54,6 +54,8 @@ lazy_static! { static ref LOGGING_CONFIG: Mutex = Mutex::new(LoggingConfig::default()); } +const LOGGING_PATTERN: &str = "{d(%Y%m%d %H:%M:%S%.3f)} {h({l})} {M} - {m}{n}"; + /// This filter is rejecting messages that doesn't start with "grin" /// in order to save log space for only Grin-related records #[derive(Debug)] @@ -97,7 +99,7 @@ pub fn init_logger(config: Option) { // Start logger let stdout = ConsoleAppender::builder() - .encoder(Box::new(PatternEncoder::default())) + .encoder(Box::new(PatternEncoder::new(&LOGGING_PATTERN))) .build(); let mut root = Root::builder(); @@ -132,7 +134,7 @@ pub fn init_logger(config: Option) { Box::new( RollingFileAppender::builder() .append(c.log_file_append) - .encoder(Box::new(PatternEncoder::new("{d} {l} {M} - {m}{n}"))) + .encoder(Box::new(PatternEncoder::new(&LOGGING_PATTERN))) .build(c.log_file_path, Box::new(policy)) .unwrap(), ) @@ -140,7 +142,7 @@ pub fn init_logger(config: Option) { Box::new( FileAppender::builder() .append(c.log_file_append) - .encoder(Box::new(PatternEncoder::new("{d} {l} {M} - {m}{n}"))) + .encoder(Box::new(PatternEncoder::new(&LOGGING_PATTERN))) .build(c.log_file_path) .unwrap(), )