From 08a277f8d1370b9d3421e9060c0a00a1f7f47999 Mon Sep 17 00:00:00 2001 From: Simon B Date: Sun, 19 Nov 2017 19:34:43 +0100 Subject: [PATCH] Log "nn.nnn coins spent using strategy ..." on log level Debug (#326) * Log "nn.nnn coins spent using strategy ..." on log level Debug * util::logger whitespace/cleanup Add code comment about LOGGING_CONFIG injection --- src/bin/grin.rs | 2 +- util/src/logger.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin/grin.rs b/src/bin/grin.rs index f4d82f47..dcd911f9 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -438,7 +438,7 @@ fn wallet_command(wallet_args: &ArgMatches) { (selection_strategy == "all"), ); match result { - Ok(_) => {}, //success messaged logged internally + Ok(_) => { debug!(LOGGER, "{} coins sent using strategy {} to {}", amount.to_string(), selection_strategy, dest) }, //success messaged logged internally Err(wallet::Error::NotEnoughFunds(_)) => {}, Err(e) => panic!(e), }; diff --git a/util/src/logger.rs b/util/src/logger.rs index fa91aea7..30867f20 100644 --- a/util/src/logger.rs +++ b/util/src/logger.rs @@ -33,10 +33,11 @@ fn convert_log_level(in_level: &LogLevel) -> Level { } lazy_static! { - /// Flag to observe whether logging was explcitly initialised (don't output otherwise) + /// Flag to observe whether logging was explicitly initialised (don't output otherwise) static ref WAS_INIT: Mutex = Mutex::new(false); /// Static Logging configuration, should only be set once, before first logging call static ref LOGGING_CONFIG: Mutex = Mutex::new(LoggingConfig::default()); + /// And a static reference to the logger itself, accessible from all crates pub static ref LOGGER: Logger = { let was_init = WAS_INIT.lock().unwrap().clone(); @@ -49,15 +50,13 @@ lazy_static! { let terminal_drain = slog_term::FullFormat::new(terminal_decorator).build().fuse(); let terminal_drain = LevelFilter::new(terminal_drain, slog_level_stdout).fuse(); let mut terminal_drain = slog_async::Async::new(terminal_drain).build().fuse(); - if !config.log_to_stdout || !was_init { terminal_drain = slog_async::Async::new(Discard{}).build().fuse(); } + //File drain let mut file_drain_final = slog_async::Async::new(Discard{}).build().fuse(); - if config.log_to_file && was_init { - //File drain let file = OpenOptions::new() .create(true) .write(true) @@ -81,13 +80,14 @@ lazy_static! { } /// Initialises the logger with the given configuration - pub fn init_logger(config: Option) { if let Some(c) = config { let mut config_ref = LOGGING_CONFIG.lock().unwrap(); *config_ref = c.clone(); + // Logger configuration successfully injected into LOGGING_CONFIG... let mut was_init_ref = WAS_INIT.lock().unwrap(); *was_init_ref = true; + // .. allow logging, having ensured that paths etc are immutable } }