fix: init_test_logger update for log4rs (#1921)

This commit is contained in:
Gary Yu 2018-11-05 11:57:59 +08:00 committed by GitHub
parent f276de1719
commit d56ef364c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -187,8 +187,47 @@ pub fn init_test_logger() {
let mut logger = LoggingConfig::default();
logger.log_to_file = false;
logger.stdout_log_level = LogLevel::Debug;
// Save current logging configuration
let mut config_ref = LOGGING_CONFIG.lock();
*config_ref = logger;
let level_stdout = convert_log_level(&config_ref.stdout_log_level);
let level_minimum = level_stdout; // minimum logging level for Root logger
// Start logger
let stdout = ConsoleAppender::builder()
.encoder(Box::new(PatternEncoder::default()))
.build();
let mut root = Root::builder();
let mut appenders = vec![];
{
let filter = Box::new(ThresholdFilter::new(level_stdout));
appenders.push(
Appender::builder()
.filter(filter)
.filter(Box::new(GrinFilter))
.build("stdout", Box::new(stdout)),
);
root = root.appender("stdout");
}
let config = Config::builder()
.appenders(appenders)
.build(root.build(level_minimum))
.unwrap();
let _ = log4rs::init_config(config).unwrap();
info!(
"log4rs is initialized, stdout level: {:?}, min. level: {:?}",
level_stdout, level_minimum
);
*was_init_ref = true;
}