Switch from stderrlog to env_logger
This commit is contained in:
parent
b883c660fc
commit
b4e98a4dd1
3 changed files with 37 additions and 59 deletions
61
Cargo.lock
generated
61
Cargo.lock
generated
|
|
@ -57,17 +57,6 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi 0.1.19",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
|
|
@ -214,6 +203,17 @@ version = "1.8.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
|
||||
dependencies = [
|
||||
"is-terminal",
|
||||
"log",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.0"
|
||||
|
|
@ -290,15 +290,6 @@ version = "0.14.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
|
|
@ -457,12 +448,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||
|
||||
[[package]]
|
||||
name = "oxipng"
|
||||
version = "8.0.0"
|
||||
|
|
@ -470,6 +455,7 @@ dependencies = [
|
|||
"bitvec",
|
||||
"clap",
|
||||
"crossbeam-channel",
|
||||
"env_logger",
|
||||
"filetime",
|
||||
"image",
|
||||
"indexmap",
|
||||
|
|
@ -479,7 +465,6 @@ dependencies = [
|
|||
"rgb",
|
||||
"rustc-hash",
|
||||
"rustc_version",
|
||||
"stderrlog",
|
||||
"wild",
|
||||
"zopfli",
|
||||
]
|
||||
|
|
@ -590,18 +575,6 @@ version = "0.3.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "238abfbb77c1915110ad968465608b68e869e0772622c9656714e73e5a1a522f"
|
||||
|
||||
[[package]]
|
||||
name = "stderrlog"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69a26bbf6de627d389164afa9783739b56746c6c72c4ed16539f4ff54170327b"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"log",
|
||||
"termcolor",
|
||||
"thread_local",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
|
|
@ -623,16 +596,6 @@ dependencies = [
|
|||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typed-arena"
|
||||
version = "2.0.2"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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"]
|
||||
|
|
|
|||
26
src/main.rs
26
src/main.rs
|
|
@ -18,7 +18,7 @@ mod rayon;
|
|||
|
||||
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;
|
||||
|
|
@ -26,6 +26,7 @@ use oxipng::StripChunks;
|
|||
use oxipng::{InFile, OutFile};
|
||||
use rayon::prelude::*;
|
||||
use std::fs::DirBuilder;
|
||||
use std::io::Write;
|
||||
#[cfg(feature = "zopfli")]
|
||||
use std::num::NonZeroU8;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -386,13 +387,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(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue