Skip to content

Commit

Permalink
[0.25.2] Replace dep. atty with is-terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
emabee committed Mar 2, 2023
1 parent 35d1321 commit 792a2c3
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 56 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.25.2] - 2023-03-02

Replace dependency `atty` with `is-terminal`, due to
[RUSTSEC-2021-0145](https://rustsec.org/advisories/RUSTSEC-2021-0145).

## [0.25.1] - 2023-02-06

Use chrono's support for rfc3339. Improve tests for `DeferredNow`.
Expand Down
44 changes: 23 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flexi_logger"
version = "0.25.1"
version = "0.25.2"
authors = ["emabee <meinolf.block@sap.com>"]
categories = ["development-tools::debugging"]
description = """
Expand Down Expand Up @@ -30,37 +30,39 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = ["colors", "textfilter"]
async = ["crossbeam-channel", "crossbeam-queue"]
colors = ["nu-ansi-term", "atty"]
colors = ["nu-ansi-term", "is-terminal"]
compress = ["flate2"]
dont_minimize_extra_stacks = []
specfile = ["specfile_without_notification","notify-debouncer-mini"]
specfile_without_notification = ["serde","toml","serde_derive"]
specfile = ["specfile_without_notification", "notify-debouncer-mini"]
specfile_without_notification = ["serde", "toml", "serde_derive"]
syslog_writer = ["libc", "hostname"]
textfilter = ["regex"]
trc =["async", "specfile", "tracing","tracing-subscriber"]
trc = ["async", "specfile", "tracing", "tracing-subscriber"]

[dependencies]
atty = {version = "0.2", optional = true}
nu-ansi-term = {version = "0.46", optional = true}
chrono = {version = "0.4.22", default-features = false, features = ["clock"]}
crossbeam-channel = {version = "0.5", optional = true}
crossbeam-queue = {version = "0.3", optional = true}
flate2 = {version = "1.0", optional = true}
is-terminal = { version = "0.4", optional = true }
nu-ansi-term = { version = "0.46", optional = true }
chrono = { version = "0.4.22", default-features = false, features = ["clock"] }
crossbeam-channel = { version = "0.5", optional = true }
crossbeam-queue = { version = "0.3", optional = true }
flate2 = { version = "1.0", optional = true }
glob = "0.3"
hostname = {version = "0.3", optional = true}
hostname = { version = "0.3", optional = true }
lazy_static = "1.4"
log = {version = "0.4", features = ["std"]}
notify-debouncer-mini = {version = "0.2", optional = true, default-features = false}
regex = {version = "1.1", optional = true}
serde = {version = "1.0", optional = true}
serde_derive = {version = "1.0", optional = true}
log = { version = "0.4", features = ["std"] }
notify-debouncer-mini = { version = "0.2", optional = true, default-features = false }
regex = { version = "1.1", optional = true }
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }
thiserror = "1.0"
toml = {version = "0.7", optional = true }
tracing-subscriber = {version = "0.3", optional = true, features = ["env-filter"]}
tracing = {version = "0.1.36", optional = true}
toml = { version = "0.7", optional = true }
tracing-subscriber = { version = "0.3", optional = true, features = [
"env-filter",
] }
tracing = { version = "0.1.36", optional = true }

[target.'cfg(linux)'.dependencies]
libc = {version = "^0.2.50", optional = true}
libc = { version = "^0.2.50", optional = true }

[dev-dependencies]
serde_derive = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The default feature `colors` simplifies this by doing three things:
* provides additional colored pendants to the existing uncolored format functions
* it uses `colored_default_format()` for the output to stderr,
and the non-colored `default_format()` for the output to files
* it activates the optional dependency to `atty` to being able to switch off
* it activates the optional dependency to `is-terminal` to being able to switch off
coloring if the output is not sent to a terminal but e.g. piped to another program.

**<span style="color:red">C</span><span style="color:blue">o</span><span
Expand All @@ -110,7 +110,7 @@ style="color:magenta">r</span><span style="color:darkturquoise">s</span>**,
or styles in general, are a matter of taste, and no choice will fit every need.
So you can override the default formatting and coloring in various ways.

With switching off the default features and choosing feature `atty` explicitly
With switching off the default features and choosing feature `is-terminal` explicitly
(see [usage](#usage)) you can remove the `nu_ansi_term`-based coloring
but keep the capability to switch off your own coloring.

Expand Down
6 changes: 3 additions & 3 deletions examples/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {

#[cfg(feature = "colors")]
{
use atty::Stream::{Stderr, Stdout};
use is_terminal::IsTerminal;
use nu_ansi_term::Color;

for i in 0..=255 {
Expand All @@ -13,7 +13,7 @@ fn main() {

println!();

if atty::is(Stdout) {
if std::io::stdout().is_terminal() {
println!(
"Stdout is considered a tty - \
flexi_logger::AdaptiveFormat will use colors",
Expand All @@ -25,7 +25,7 @@ fn main() {
);
}

if atty::is(Stderr) {
if std::io::stderr().is_terminal() {
println!(
"Stderr is considered a tty - \
flexi_logger::AdaptiveFormat will use colors",
Expand Down
6 changes: 3 additions & 3 deletions examples/colors2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {

// #[cfg(feature = "colors")]
// {
// use atty::Stream::{Stderr, Stdout};
// use is_terminal::IsTerminal;;

// colored::control::set_override(true);

Expand All @@ -34,7 +34,7 @@ fn main() {

// println!();

// if atty::is(Stdout) {
// if std::io::stdout().is_terminal() {
// println!(
// "Stdout is considered a tty - \
// flexi_logger::AdaptiveFormat will use colors",
Expand All @@ -46,7 +46,7 @@ fn main() {
// );
// }

// if atty::is(Stderr) {
// if std::io::stderr().is_terminal() {
// println!(
// "Stderr is considered a tty - \
// flexi_logger::AdaptiveFormat will use colors",
Expand Down
9 changes: 5 additions & 4 deletions scripts/qualify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ fn main() {

// Build in important variants
std::fs::remove_file("Cargo.lock").ok();
run_command!("cargo", "+1.60.0", "build", "--no-default-features");
run_command!("cargo", "+1.60.0", "build", "--all-features");
run_command!("cargo", "+1.60", "build", "--no-default-features");
run_command!("cargo", "+1.60", "build", "--all-features");

std::fs::remove_file("Cargo.lock").ok();
run_command!("cargo", "build");
run_command!("cargo", "build", "--no-default-features");
run_command!("cargo", "build", "--no-default-features", "--features=atty");
#[rustfmt::skip]
run_command!("cargo", "build", "--no-default-features", "--features=is-terminal");
run_command!("cargo", "build", "--all-features");
run_command!("cargo", "build", "--release");
run_command!("cargo", "build", "--release", "--all-features");
Expand All @@ -65,7 +66,7 @@ fn main() {
run_command!("cargo", "+nightly", "clippy", "--all-targets", "--all-features", "--", "-D", "warnings");

// Run tests in important variants
run_command!("cargo", "+1.60.0", "test", "--all-features");
run_command!("cargo", "+1.60", "test", "--all-features");
run_command!("cargo", "test", "--release", "--all-features");
run_command!("cargo", "test", "--no-default-features");
run_command!("cargo", "test", "--release");
Expand Down
6 changes: 3 additions & 3 deletions src/code_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@
//! by providing one of the variants of [`AdaptiveFormat`](crate::AdaptiveFormat) to the respective
//! format method, e.g.
//! ```rust
//! # #[cfg(feature = "atty")]
//! # #[cfg(feature = "is-terminal")]
//! # use flexi_logger::AdaptiveFormat;
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # #[cfg(feature = "atty")]
//! # #[cfg(feature = "is-terminal")]
//! # {
//! flexi_logger::Logger::try_with_str("info")?
//! .adaptive_format_for_stderr(AdaptiveFormat::Detailed);
Expand All @@ -244,7 +244,7 @@
//! `flexi_logger` initializes by default equivalently to this:
//!
//! ```rust
//! # #[cfg(feature = "atty")]
//! # #[cfg(feature = "is-terminal")]
//! # mod example {
//! # use flexi_logger::{Logger,AdaptiveFormat,default_format, FileSpec};
//! # use log::{debug, error, info, trace, warn};
Expand Down
6 changes: 3 additions & 3 deletions src/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ fn parse_style(input: &str) -> Result<Style, std::num::ParseIntError> {
///
/// This is helpful if the output is sometimes piped into other programs, which usually
/// do not expect color control byte sequences.
#[cfg_attr(docsrs, doc(cfg(feature = "atty")))]
#[cfg(feature = "atty")]
#[cfg_attr(docsrs, doc(cfg(feature = "is-terminal")))]
#[cfg(feature = "is-terminal")]
#[derive(Clone, Copy)]
pub enum AdaptiveFormat {
/// Chooses between [`default_format`](crate::default_format)
Expand Down Expand Up @@ -338,7 +338,7 @@ pub enum AdaptiveFormat {
Custom(FormatFunction, FormatFunction),
}

#[cfg(feature = "atty")]
#[cfg(feature = "is-terminal")]
impl AdaptiveFormat {
#[must_use]
pub(crate) fn format_function(self, is_tty: bool) -> FormatFunction {
Expand Down
40 changes: 23 additions & 17 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ use std::{
time::Duration,
};

#[cfg(feature = "atty")]
#[cfg(feature = "is-terminal")]
use crate::formats::AdaptiveFormat;
#[cfg(feature = "is-terminal")]
use is_terminal::IsTerminal;

#[cfg(feature = "specfile_without_notification")]
use {crate::logger_handle::LogSpecSubscriber, std::io::Read, std::path::Path};
Expand Down Expand Up @@ -133,17 +135,21 @@ impl Logger {
format_for_file: default_format,

#[cfg(feature = "colors")]
format_for_stdout: AdaptiveFormat::Default.format_function(if cfg!(feature = "atty") {
atty::is(atty::Stream::Stdout)
} else {
false
}),
format_for_stdout: AdaptiveFormat::Default.format_function(
if cfg!(feature = "is-terminal") {
std::io::stdout().is_terminal()
} else {
false
},
),
#[cfg(feature = "colors")]
format_for_stderr: AdaptiveFormat::Default.format_function(if cfg!(feature = "atty") {
atty::is(atty::Stream::Stderr)
} else {
false
}),
format_for_stderr: AdaptiveFormat::Default.format_function(
if cfg!(feature = "is-terminal") {
std::io::stderr().is_terminal()
} else {
false
},
),

#[cfg(not(feature = "colors"))]
format_for_stdout: default_format,
Expand Down Expand Up @@ -306,11 +312,11 @@ impl Logger {
/// Coloring is used if `stderr` is a tty.
///
/// Regarding the default, see [`Logger::format`].
#[cfg_attr(docsrs, doc(cfg(feature = "atty")))]
#[cfg(feature = "atty")]
#[cfg_attr(docsrs, doc(cfg(feature = "is-terminal")))]
#[cfg(feature = "is-terminal")]
#[must_use]
pub fn adaptive_format_for_stderr(mut self, adaptive_format: AdaptiveFormat) -> Self {
self.format_for_stderr = adaptive_format.format_function(atty::is(atty::Stream::Stderr));
self.format_for_stderr = adaptive_format.format_function(std::io::stderr().is_terminal());
self
}

Expand All @@ -328,11 +334,11 @@ impl Logger {
/// Coloring is used if `stdout` is a tty.
///
/// Regarding the default, see [`Logger::format`].
#[cfg_attr(docsrs, doc(cfg(feature = "atty")))]
#[cfg(feature = "atty")]
#[cfg_attr(docsrs, doc(cfg(feature = "is-terminal")))]
#[cfg(feature = "is-terminal")]
#[must_use]
pub fn adaptive_format_for_stdout(mut self, adaptive_format: AdaptiveFormat) -> Self {
self.format_for_stdout = adaptive_format.format_function(atty::is(atty::Stream::Stdout));
self.format_for_stdout = adaptive_format.format_function(std::io::stdout().is_terminal());
self
}

Expand Down

0 comments on commit 792a2c3

Please sign in to comment.