mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-19 22:23:49 -07:00
logger: drop env_logger
This commit updates the `log` crate to 0.4 and drops the dependency on env_logger. In particular, the latest version of env_logger brings in additional non-optional dependencies such as chrono that I don't think is worth including into ripgrep. It turns out ripgrep doesn't need any fancy logging. We just need a concept of log levels and the ability to print to stderr. Therefore, we just roll our own super simple logger. This update is motivated by the persistent configuration task. In particular, we need the ability to toggle the global log level more than once, and this doesn't appear to be possible with older versions of the log crate.
This commit is contained in:
15
src/args.rs
15
src/args.rs
@@ -10,7 +10,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use clap;
|
||||
use encoding_rs::Encoding;
|
||||
use env_logger;
|
||||
use grep::{Grep, GrepBuilder, Error as GrepError};
|
||||
use log;
|
||||
use num_cpus;
|
||||
@@ -27,6 +26,7 @@ use printer::{ColorSpecs, Printer};
|
||||
use unescape::unescape;
|
||||
use worker::{Worker, WorkerBuilder};
|
||||
|
||||
use logger::Logger;
|
||||
use Result;
|
||||
|
||||
/// `Args` are transformed/normalized from `ArgMatches`.
|
||||
@@ -91,15 +91,14 @@ impl Args {
|
||||
pub fn parse() -> Result<Args> {
|
||||
let matches = app::app().get_matches();
|
||||
|
||||
let mut logb = env_logger::LogBuilder::new();
|
||||
if matches.is_present("debug") {
|
||||
logb.filter(None, log::LogLevelFilter::Debug);
|
||||
} else {
|
||||
logb.filter(None, log::LogLevelFilter::Warn);
|
||||
}
|
||||
if let Err(err) = logb.init() {
|
||||
if let Err(err) = Logger::init() {
|
||||
errored!("failed to initialize logger: {}", err);
|
||||
}
|
||||
if matches.is_present("debug") {
|
||||
log::set_max_level(log::LevelFilter::Debug);
|
||||
} else {
|
||||
log::set_max_level(log::LevelFilter::Warn);
|
||||
}
|
||||
ArgMatches(matches).to_args()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user