From ebd5ec084f99b3a7a3db2877e181a5e936f6c805 Mon Sep 17 00:00:00 2001 From: Philip Daniels Date: Wed, 24 Jun 2020 15:17:59 +0100 Subject: [PATCH] Do not call init_logger from inside watch. And move init_logger to main.rs for future use. --- src/main.rs | 16 ++++++++++++++++ src/run.rs | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 78340231..40045990 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::io::Write; + extern crate watchexec; use watchexec::{cli, error, run}; @@ -5,3 +7,17 @@ use watchexec::{cli, error, run}; fn main() -> error::Result<()> { run(cli::get_args()?) } + +fn init_logger(debug: bool) { + let mut log_builder = env_logger::Builder::new(); + let level = if debug { + log::LevelFilter::Debug + } else { + log::LevelFilter::Warn + }; + + log_builder + .format(|buf, r| writeln!(buf, "*** {}", r.args())) + .filter(None, level) + .init(); +} diff --git a/src/run.rs b/src/run.rs index 0a25e12b..d5561df7 100644 --- a/src/run.rs +++ b/src/run.rs @@ -10,7 +10,6 @@ use crate::watcher::{Event, Watcher}; use std::{ collections::HashMap, fs::canonicalize, - io::Write, sync::{ mpsc::{channel, Receiver}, Arc, RwLock, @@ -18,20 +17,6 @@ use std::{ time::Duration, }; -fn init_logger(debug: bool) { - let mut log_builder = env_logger::Builder::new(); - let level = if debug { - log::LevelFilter::Debug - } else { - log::LevelFilter::Warn - }; - - log_builder - .format(|buf, r| writeln!(buf, "*** {}", r.args())) - .filter(None, level) - .init(); -} - pub trait Handler { /// Called through a manual request, such as an initial run. /// @@ -76,7 +61,6 @@ where H: Handler, { let args = handler.args(); - init_logger(args.debug); let mut paths = vec![]; for path in &args.paths {