From 660cf7feb27e07bd308c3952637c5ae21c438846 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 24 Nov 2022 09:55:00 -0600 Subject: [PATCH 1/4] fix: Bump MSRV to 1.60.0 This is over 6 months old and allows us to hide optional dependencies as features so we can change them without breaking compatibility (after the first time). --- .clippy.toml | 1 + .github/workflows/ci.yml | 6 +++--- Cargo.toml | 4 ++-- src/lib.rs | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 00000000..23bf4817 --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv = "1.60.0" # MSRV diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26ba913b..643f0807 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,7 @@ jobs: - name: Run crate example run: cargo run --example default msrv: - name: "Check MSRV: 1.41.0" + name: "Check MSRV: 1.60.0" runs-on: ubuntu-latest steps: - name: Checkout repository @@ -63,7 +63,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.41.0 # MSRV + toolchain: 1.60.0 # MSRV profile: minimal override: true - uses: Swatinem/rust-cache@v1 @@ -119,7 +119,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.41.0 # MSRV + toolchain: 1.60.0 # MSRV profile: minimal override: true components: clippy diff --git a/Cargo.toml b/Cargo.toml index 961c6146..d4cbd7d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/rust-cli/env_logger/" categories = ["development-tools::debugging"] keywords = ["logging", "log", "logger"] -edition = "2018" -rust-version = "1.41.0" # MSRV +edition = "2021" +rust-version = "1.60.0" # MSRV include = [ "build.rs", "src/**/*", diff --git a/src/lib.rs b/src/lib.rs index c0ee8bd9..59fa2a3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1168,7 +1168,7 @@ pub fn init() { /// ``` /// use env_logger::{Builder, Env}; /// -/// # fn run() -> Result<(), Box<::std::error::Error>> { +/// # fn run() -> Result<(), Box> { /// let env = Env::new().filter("MY_LOG").write_style("MY_LOG_STYLE"); /// /// env_logger::try_init_from_env(env)?; From 4db5e8793162e33e17efce36057afaa41d988788 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 24 Nov 2022 09:56:36 -0600 Subject: [PATCH 2/4] fix!: Rename termcolor/atty features This makes it easier to change dependencies in the future. BREAKING CHANGE: `termcolor` -> `color` and `atty` -> `auto-color` --- Cargo.toml | 6 +++++- ci/src/main.rs | 2 +- examples/custom_format.rs | 4 ++-- src/fmt/mod.rs | 12 ++++++------ src/fmt/writer/atty.rs | 11 +++++------ src/fmt/writer/termcolor/mod.rs | 4 ++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4cbd7d6..c47dbf75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,11 @@ pre-release-replacements = [ ] [features] -default = ["termcolor", "atty", "humantime", "regex"] +default = ["auto-color", "humantime", "regex"] +color = ["dep:termcolor"] +auto-color = ["dep:atty", "color"] +humantime = ["dep:humantime"] +regex = ["dep:regex"] [dependencies] log = { version = "0.4.8", features = ["std"] } diff --git a/ci/src/main.rs b/ci/src/main.rs index e7280f1c..961a3141 100644 --- a/ci/src/main.rs +++ b/ci/src/main.rs @@ -2,7 +2,7 @@ mod permute; mod task; fn main() { - let features = ["termcolor", "humantime", "atty", "regex"]; + let features = ["color", "humantime", "auto-color", "regex"]; // Run a default build if !task::test(Default::default()) { diff --git a/examples/custom_format.rs b/examples/custom_format.rs index d8585a53..cc16b336 100644 --- a/examples/custom_format.rs +++ b/examples/custom_format.rs @@ -17,7 +17,7 @@ $ export MY_LOG_STYLE=never If you want to control the logging output completely, see the `custom_logger` example. */ -#[cfg(all(feature = "termcolor", feature = "humantime"))] +#[cfg(all(feature = "color", feature = "humantime"))] fn main() { use env_logger::{fmt::Color, Builder, Env}; @@ -50,5 +50,5 @@ fn main() { log::info!("a log from `MyLogger`"); } -#[cfg(not(all(feature = "termcolor", feature = "humantime")))] +#[cfg(not(all(feature = "color", feature = "humantime")))] fn main() {} diff --git a/src/fmt/mod.rs b/src/fmt/mod.rs index 1677887a..86c093f0 100644 --- a/src/fmt/mod.rs +++ b/src/fmt/mod.rs @@ -202,9 +202,9 @@ impl Builder { } } -#[cfg(feature = "termcolor")] +#[cfg(feature = "color")] type SubtleStyle = StyledValue<'static, &'static str>; -#[cfg(not(feature = "termcolor"))] +#[cfg(not(feature = "color"))] type SubtleStyle = &'static str; /// The default format. @@ -233,7 +233,7 @@ impl<'a> DefaultFormat<'a> { } fn subtle_style(&self, text: &'static str) -> SubtleStyle { - #[cfg(feature = "termcolor")] + #[cfg(feature = "color")] { self.buf .style() @@ -242,7 +242,7 @@ impl<'a> DefaultFormat<'a> { .clone() .into_value(text) } - #[cfg(not(feature = "termcolor"))] + #[cfg(not(feature = "color"))] { text } @@ -268,11 +268,11 @@ impl<'a> DefaultFormat<'a> { } let level = { - #[cfg(feature = "termcolor")] + #[cfg(feature = "color")] { self.buf.default_styled_level(record.level()) } - #[cfg(not(feature = "termcolor"))] + #[cfg(not(feature = "color"))] { record.level() } diff --git a/src/fmt/writer/atty.rs b/src/fmt/writer/atty.rs index 343539c1..58502168 100644 --- a/src/fmt/writer/atty.rs +++ b/src/fmt/writer/atty.rs @@ -1,13 +1,12 @@ /* This internal module contains the terminal detection implementation. -If the `atty` crate is available then we use it to detect whether we're -attached to a particular TTY. If the `atty` crate is not available we -assume we're not attached to anything. This effectively prevents styles -from being printed. +If the `auto-color` feature is enabled then we detect whether we're attached to a particular TTY. +Otherwise, assume we're not attached to anything. This effectively prevents styles from being +printed. */ -#[cfg(feature = "atty")] +#[cfg(feature = "auto-color")] mod imp { pub(in crate::fmt) fn is_stdout() -> bool { atty::is(atty::Stream::Stdout) @@ -18,7 +17,7 @@ mod imp { } } -#[cfg(not(feature = "atty"))] +#[cfg(not(feature = "auto-color"))] mod imp { pub(in crate::fmt) fn is_stdout() -> bool { false diff --git a/src/fmt/writer/termcolor/mod.rs b/src/fmt/writer/termcolor/mod.rs index f3e6768c..20f01979 100644 --- a/src/fmt/writer/termcolor/mod.rs +++ b/src/fmt/writer/termcolor/mod.rs @@ -5,8 +5,8 @@ Its public API is available when the `termcolor` crate is available. The terminal printing is shimmed when the `termcolor` crate is not available. */ -#[cfg_attr(feature = "termcolor", path = "extern_impl.rs")] -#[cfg_attr(not(feature = "termcolor"), path = "shim_impl.rs")] +#[cfg_attr(feature = "color", path = "extern_impl.rs")] +#[cfg_attr(not(feature = "color"), path = "shim_impl.rs")] mod imp; pub(in crate::fmt) use self::imp::*; From 066c2192c187f047ae178e786ff36e6cabed21f7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 24 Nov 2022 10:01:18 -0600 Subject: [PATCH 3/4] fix: Replace atty with is_terminal --- Cargo.lock | 145 +++++++++++++++++++++++++++++++++++++---- Cargo.toml | 4 +- src/fmt/writer/atty.rs | 6 +- 3 files changed, 140 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 337e0554..4caf4b5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.19" @@ -10,15 +12,16 @@ dependencies = [ ] [[package]] -name = "atty" -version = "0.2.14" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cc" +version = "1.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" [[package]] name = "cfg-if" @@ -34,18 +37,39 @@ version = "0.0.0" name = "env_logger" version = "0.9.3" dependencies = [ - "atty", "humantime", + "is-terminal", "log", "regex", "termcolor", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] @@ -56,12 +80,40 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "io-lifetimes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d367024b3f3414d8e01f437f704f41a9f64ab36f9067fa73e526ad4c763c87" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae5bc6e2eb41c9def29a3e0f1306382807764b9b53112030eff57435667352d" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "libc" version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +[[package]] +name = "linux-raw-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" + [[package]] name = "log" version = "0.4.17" @@ -94,6 +146,20 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "rustix" +version = "0.36.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "termcolor" version = "1.1.3" @@ -133,3 +199,60 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/Cargo.toml b/Cargo.toml index c47dbf75..8f0e71dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ pre-release-replacements = [ [features] default = ["auto-color", "humantime", "regex"] color = ["dep:termcolor"] -auto-color = ["dep:atty", "color"] +auto-color = ["dep:is-terminal", "color"] humantime = ["dep:humantime"] regex = ["dep:regex"] @@ -48,7 +48,7 @@ log = { version = "0.4.8", features = ["std"] } regex = { version = "1.0.3", optional = true, default-features=false, features=["std", "perf"] } termcolor = { version = "1.1.1", optional = true } humantime = { version = "2.0.0", optional = true } -atty = { version = "0.2.5", optional = true } +is-terminal = { version = "0.4.0", optional = true } [[test]] name = "regexp_filter" diff --git a/src/fmt/writer/atty.rs b/src/fmt/writer/atty.rs index 58502168..1a133eef 100644 --- a/src/fmt/writer/atty.rs +++ b/src/fmt/writer/atty.rs @@ -8,12 +8,14 @@ printed. #[cfg(feature = "auto-color")] mod imp { + use is_terminal::IsTerminal; + pub(in crate::fmt) fn is_stdout() -> bool { - atty::is(atty::Stream::Stdout) + std::io::stdout().is_terminal() } pub(in crate::fmt) fn is_stderr() -> bool { - atty::is(atty::Stream::Stderr) + std::io::stderr().is_terminal() } } From d55d26980f338179e5d1829fb8d16b1d509530f1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 24 Nov 2022 11:49:01 -0600 Subject: [PATCH 4/4] style: Make clippy happy --- ci/src/task.rs | 2 +- src/fmt/writer/mod.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/src/task.rs b/ci/src/task.rs index b6740549..5ef844e7 100644 --- a/ci/src/task.rs +++ b/ci/src/task.rs @@ -58,7 +58,7 @@ pub fn test(args: TestArgs) -> bool { } if let Some(features) = &features { - command.args(&["--features", features]); + command.args(["--features", features]); } println!("running {:?}", command); diff --git a/src/fmt/writer/mod.rs b/src/fmt/writer/mod.rs index 2b56772e..7f4b6f94 100644 --- a/src/fmt/writer/mod.rs +++ b/src/fmt/writer/mod.rs @@ -165,6 +165,7 @@ impl Builder { } /// Whether or not to capture logs for `cargo test`. + #[allow(clippy::wrong_self_convention)] pub(crate) fn is_test(&mut self, is_test: bool) -> &mut Self { self.is_test = is_test; self