Do not call init_logger from inside watch.

And move init_logger to main.rs for future use.
This commit is contained in:
Philip Daniels 2020-06-24 15:17:59 +01:00
parent 6f6fb0ceb2
commit ebd5ec084f
2 changed files with 16 additions and 16 deletions

View file

@ -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();
}

View file

@ -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 {