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 {