Skip to content

Commit

Permalink
Switch from stderrlog to env_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
andrews05 committed Jul 11, 2023
1 parent 31e796c commit a986794
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 59 deletions.
61 changes: 12 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ rgb = "0.8.36"
indexmap = "2.0.0"
libdeflater = "0.14.0"
log = "0.4.19"
stderrlog = { version = "0.5.4", optional = true, default-features = false }
bitvec = "1.0.1"
rustc-hash = "1.1.0"

[dependencies.env_logger]
optional = true
default-features = false
features = ["auto-color"]
version = "0.10.0"

[dependencies.crossbeam-channel]
optional = true
version = "0.5.8"
Expand Down Expand Up @@ -66,7 +71,7 @@ version = "0.24.6"
rustc_version = "0.4.0"

[features]
binary = ["clap", "wild", "stderrlog"]
binary = ["clap", "wild", "env_logger"]
default = ["binary", "filetime", "parallel", "zopfli"]
parallel = ["rayon", "indexmap/rayon", "crossbeam-channel"]
freestanding = ["libdeflater/freestanding"]
Expand Down
26 changes: 18 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
use indexmap::IndexSet;
use log::{error, warn};
use log::{error, warn, Level, LevelFilter};
use oxipng::Deflaters;
use oxipng::Options;
use oxipng::RowFilter;
use oxipng::StripChunks;
use oxipng::{InFile, OutFile};
use std::fs::DirBuilder;
use std::io::Write;
#[cfg(feature = "zopfli")]
use std::num::NonZeroU8;
use std::path::PathBuf;
Expand Down Expand Up @@ -384,13 +385,22 @@ fn collect_files(
fn parse_opts_into_struct(
matches: &ArgMatches,
) -> Result<(OutFile, Option<PathBuf>, Options), String> {
stderrlog::new()
.module(module_path!())
.quiet(matches.get_flag("quiet"))
.verbosity(matches.get_count("verbose") as usize + 2)
.show_level(false)
.init()
.unwrap();
let log_level = match matches.get_count("verbose") {
_ if matches.get_flag("quiet") => LevelFilter::Off,
0 => LevelFilter::Info,
1 => LevelFilter::Debug,
_ => LevelFilter::Trace,
};
env_logger::builder()
.filter_module(module_path!(), log_level)
.format(|buf, record| {
let style = match record.level() {
Level::Info => buf.style(),
_ => buf.default_level_style(record.level()),
};
writeln!(buf, "{}", style.value(record.args()))
})
.init();

let mut opts = match matches.get_one::<String>("optimization") {
None => Options::default(),
Expand Down

0 comments on commit a986794

Please sign in to comment.