Safe coloured logging.

This commit is contained in:
Gav Wood
2016-06-29 17:16:58 +02:00
committed by arkpar
parent 4a6206c514
commit 92edf7f511
8 changed files with 33 additions and 10 deletions

View File

@@ -184,7 +184,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
let panic_handler = PanicHandler::new_in_arc();
// Setup logging
let logger = setup_log::setup_log(&conf.args.flag_logging);
let logger = setup_log::setup_log(&conf.args.flag_logging, conf.args.flag_no_color);
// Raise fdlimit
unsafe { ::fdlimit::raise_fd_limit(); }
@@ -320,6 +320,8 @@ fn execute_export(conf: Configuration) {
// Setup panic handler
let panic_handler = PanicHandler::new_in_arc();
// Setup logging
let _logger = setup_log::setup_log(&conf.args.flag_logging, conf.args.flag_no_color);
// Raise fdlimit
unsafe { ::fdlimit::raise_fd_limit(); }
@@ -392,6 +394,8 @@ fn execute_import(conf: Configuration) {
// Setup panic handler
let panic_handler = PanicHandler::new_in_arc();
// Setup logging
let _logger = setup_log::setup_log(&conf.args.flag_logging, conf.args.flag_no_color);
// Raise fdlimit
unsafe { ::fdlimit::raise_fd_limit(); }

View File

@@ -19,10 +19,10 @@ use std::env;
use std::sync::Arc;
use time;
use env_logger::LogBuilder;
use util::{RotatingLogger};
use util::RotatingLogger;
/// Sets up the logger
pub fn setup_log(init: &Option<String>) -> Arc<RotatingLogger> {
pub fn setup_log(init: &Option<String>, enable_color: bool) -> Arc<RotatingLogger> {
use rlog::*;
let mut levels = String::new();
@@ -43,7 +43,7 @@ pub fn setup_log(init: &Option<String>) -> Arc<RotatingLogger> {
builder.parse(s);
}
let logs = Arc::new(RotatingLogger::new(levels));
let logs = Arc::new(RotatingLogger::new(levels, enable_color));
let logger = logs.clone();
let format = move |record: &LogRecord| {
let timestamp = time::strftime("%Y-%m-%d %H:%M:%S %Z", &time::now()).unwrap();