Skip to content

Commit

Permalink
subscriber: replace unmaintained ansi_term with nu-ansi-term (#2287)
Browse files Browse the repository at this point in the history
This increases the MSRV of `tracing-subscriber` to 1.50+.

## Motivation

[ansi_term] last time update is over 2 years ago, use
nushell team forked [nu-ansi-term] instead

## Solution

Use [nu-ansi-term].

Closes #2040

[nu-ansi-term]: https://github.com/nushell/nu-ansi-term
[ansi_term]: https://github.com/ogham/rust-ansi-term
  • Loading branch information
poliorcetics authored and hawkw committed Oct 6, 2022
1 parent a4fc92c commit 605c2ef
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 78 deletions.
76 changes: 32 additions & 44 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,50 +179,38 @@ jobs:
name: "cargo check (MSRV on ubuntu-latest)"
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "install Rust ${{ env.MSRV }}"
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.MSRV }}
profile: minimal
- name: "install Rust nightly"
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
- name: Select minimal versions
uses: actions-rs/cargo@v1
with:
command: update
args: -Z minimal-versions
toolchain: nightly
- name: Check
uses: actions-rs/cargo@v1
with:
command: check
# skip the following crates:
# - tracing-appender, as it has its own MSRV.
# TODO(eliza): remove this when appender is on the same MSRV as
# everything else
# - the examples, as they are not published & we don't care about
# MSRV support for them.
# - tracing-futures, as it depends on ancient tokio versions.
# TODO(eliza): remove this when the ancient tokio deps are dropped
args: >-
--workspace --all-features --locked
--exclude=tracing-appender
--exclude=tracing-examples
--exclude=tracing-futures
--exclude=tracing-opentelemetry
toolchain: ${{ env.MSRV }}

# TODO: remove this once tracing's MSRV is bumped.
check-msrv-appender:
# Run `cargo check` on our minimum supported Rust version (1.53.0).
name: "cargo check (tracing-appender MSRV)"
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
# cargo hack --feature-powerset will have a significant permutation
# number, we can't just use --all as it increases the runtime
# further than what we would like to
subcrate:
- tracing-appender
- tracing-attributes
- tracing-core
- tracing-futures
- tracing-log
- tracing-macros
- tracing-serde
- tracing-subscriber
- tracing-tower
- tracing-opentelemetry
- tracing
toolchain:
- 1.49.0
- stable
# TODO(eliza): remove this when appender is on the same MSRV.
# same for tracing subscriber
exclude:
- subcrate: tracing-appender
toolchain: 1.49.0
- subcrate: tracing-subscriber
toolchain: 1.49.0
include:
- subcrate: tracing-appender
toolchain: 1.53.0
- subcrate: tracing-subscriber
toolchain: 1.50.0
steps:
- uses: actions/checkout@v3
- name: "install Rust ${{ env.APPENDER_MSRV }}"
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bytes = "1"
argh = "0.1.8"

# sloggish example
ansi_term = "0.12.1"
nu-ansi-term = "0.46.0"
humantime = "2.1.0"
log = "0.4.17"

Expand Down
4 changes: 2 additions & 2 deletions examples/examples/sloggish/sloggish_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//!
//! [`slog-term`]: https://docs.rs/slog-term/2.4.0/slog_term/
//! [`slog` README]: https://github.com/slog-rs/slog#terminal-output-example
use ansi_term::{Color, Style};
use nu_ansi_term::{Color, Style};
use tracing::{
field::{Field, Visit},
Id, Level, Subscriber,
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<'a> Visit for Event<'a> {
write!(
&mut self.stderr,
"{}",
// Have to alloc here due to `ansi_term`'s API...
// Have to alloc here due to `nu_ansi_term`'s API...
Style::new().bold().paint(format!("{:?}", value))
)
.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions tracing-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ categories = [
"asynchronous",
]
keywords = ["logging", "tracing", "metrics", "subscriber"]
rust-version = "1.49.0"
rust-version = "1.50.0"

[features]

Expand All @@ -29,7 +29,7 @@ alloc = []
std = ["alloc", "tracing-core/std"]
env-filter = ["matchers", "regex", "once_cell", "tracing", "std", "thread_local"]
fmt = ["registry", "std"]
ansi = ["fmt", "ansi_term"]
ansi = ["fmt", "nu-ansi-term"]
registry = ["sharded-slab", "thread_local", "std"]
json = ["tracing-serde", "serde", "serde_json"]
valuable = ["tracing-core/valuable", "valuable_crate", "valuable-serde", "tracing-serde/valuable"]
Expand All @@ -49,7 +49,7 @@ once_cell = { optional = true, version = "1.13.0" }

# fmt
tracing-log = { path = "../tracing-log", version = "0.1.3", optional = true, default-features = false, features = ["log-tracer", "std"] }
ansi_term = { version = "0.12.1", optional = true }
nu-ansi-term = { version = "0.46.0", optional = true }
time = { version = "0.3.2", features = ["formatting"], optional = true }

# only required by the json feature
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ Utilities for implementing and composing [`tracing`][tracing] subscribers.
[discord-url]: https://discord.gg/EeF3cQw
[maint-badge]: https://img.shields.io/badge/maintenance-experimental-blue.svg

*Compiler support: [requires `rustc` 1.49+][msrv]*
*Compiler support: [requires `rustc` 1.50+][msrv]*

[msrv]: #supported-rust-versions

## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.49. The current Tracing version is not guaranteed to build on Rust
version is 1.50. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down
16 changes: 8 additions & 8 deletions tracing-subscriber/src/filter/env/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ impl Builder {
}

if !disabled.is_empty() {
#[cfg(feature = "ansi_term")]
use ansi_term::{Color, Style};
#[cfg(feature = "nu_ansi_term")]
use nu_ansi_term::{Color, Style};
// NOTE: We can't use a configured `MakeWriter` because the EnvFilter
// has no knowledge of any underlying subscriber or collector, which
// may or may not use a `MakeWriter`.
let warn = |msg: &str| {
#[cfg(not(feature = "ansi_term"))]
#[cfg(not(feature = "nu_ansi_term"))]
let msg = format!("warning: {}", msg);
#[cfg(feature = "ansi_term")]
#[cfg(feature = "nu_ansi_term")]
let msg = {
let bold = Style::new().bold();
let mut warning = Color::Yellow.paint("warning");
Expand All @@ -227,9 +227,9 @@ impl Builder {
eprintln!("{}", msg);
};
let ctx_prefixed = |prefix: &str, msg: &str| {
#[cfg(not(feature = "ansi_term"))]
#[cfg(not(feature = "nu_ansi_term"))]
let msg = format!("{} {}", prefix, msg);
#[cfg(feature = "ansi_term")]
#[cfg(feature = "nu_ansi_term")]
let msg = {
let mut equal = Color::Fixed(21).paint("="); // dark blue
equal.style_ref_mut().is_bold = true;
Expand All @@ -240,9 +240,9 @@ impl Builder {
let ctx_help = |msg| ctx_prefixed("help:", msg);
let ctx_note = |msg| ctx_prefixed("note:", msg);
let ctx = |msg: &str| {
#[cfg(not(feature = "ansi_term"))]
#[cfg(not(feature = "nu_ansi_term"))]
let msg = format!("note: {}", msg);
#[cfg(feature = "ansi_term")]
#[cfg(feature = "nu_ansi_term")]
let msg = {
let mut pipe = Color::Fixed(21).paint("|");
pipe.style_ref_mut().is_bold = true;
Expand Down
20 changes: 10 additions & 10 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use tracing_core::{
use tracing_log::NormalizeEvent;

#[cfg(feature = "ansi")]
use ansi_term::{Colour, Style};
use nu_ansi_term::{Color, Style};

#[cfg(feature = "json")]
mod json;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub use pretty::*;
/// does not support ANSI escape codes (such as a log file), and they should
/// not be emitted.
///
/// Crates like [`ansi_term`] and [`owo-colors`] can be used to add ANSI
/// Crates like [`nu_ansi_term`] and [`owo-colors`] can be used to add ANSI
/// escape codes to formatted output.
///
/// * The actual [`Event`] to be formatted.
Expand Down Expand Up @@ -189,7 +189,7 @@ pub use pretty::*;
/// [implements `FormatFields`]: super::FmtContext#impl-FormatFields<'writer>
/// [ANSI terminal escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code
/// [`Writer::has_ansi_escapes`]: Writer::has_ansi_escapes
/// [`ansi_term`]: https://crates.io/crates/ansi_term
/// [`nu_ansi_term`]: https://crates.io/crates/nu_ansi_term
/// [`owo-colors`]: https://crates.io/crates/owo-colors
/// [default formatter]: Full
pub trait FormatEvent<S, N>
Expand Down Expand Up @@ -1483,13 +1483,13 @@ impl<'a> fmt::Display for FmtLevel<'a> {
impl<'a> fmt::Display for FmtLevel<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.ansi {
match *self.level {
Level::TRACE => write!(f, "{}", Colour::Purple.paint(TRACE_STR)),
Level::DEBUG => write!(f, "{}", Colour::Blue.paint(DEBUG_STR)),
Level::INFO => write!(f, "{}", Colour::Green.paint(INFO_STR)),
Level::WARN => write!(f, "{}", Colour::Yellow.paint(WARN_STR)),
Level::ERROR => write!(f, "{}", Colour::Red.paint(ERROR_STR)),
}
return match *self.level {
Level::TRACE => write!(f, "{}", Color::Purple.paint(TRACE_STR)),
Level::DEBUG => write!(f, "{}", Color::Blue.paint(DEBUG_STR)),
Level::INFO => write!(f, "{}", Color::Green.paint(INFO_STR)),
Level::WARN => write!(f, "{}", Color::Yellow.paint(WARN_STR)),
Level::ERROR => write!(f, "{}", Color::Red.paint(ERROR_STR)),
};
} else {
match *self.level {
Level::TRACE => f.pad(TRACE_STR),
Expand Down
12 changes: 6 additions & 6 deletions tracing-subscriber/src/fmt/format/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tracing_core::{
#[cfg(feature = "tracing-log")]
use tracing_log::NormalizeEvent;

use ansi_term::{Colour, Style};
use nu_ansi_term::{Color, Style};

/// An excessively pretty, human-readable event formatter.
///
Expand Down Expand Up @@ -143,11 +143,11 @@ impl Default for Pretty {
impl Pretty {
fn style_for(level: &Level) -> Style {
match *level {
Level::TRACE => Style::new().fg(Colour::Purple),
Level::DEBUG => Style::new().fg(Colour::Blue),
Level::INFO => Style::new().fg(Colour::Green),
Level::WARN => Style::new().fg(Colour::Yellow),
Level::ERROR => Style::new().fg(Colour::Red),
Level::TRACE => Style::new().fg(Color::Purple),
Level::DEBUG => Style::new().fg(Color::Blue),
Level::INFO => Style::new().fg(Color::Green),
Level::WARN => Style::new().fg(Color::Yellow),
Level::ERROR => Style::new().fg(Color::Red),
}
}

Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! `tracing-subscriber` is intended for use by both `Subscriber` authors and
//! application authors using `tracing` to instrument their applications.
//!
//! *Compiler support: [requires `rustc` 1.49+][msrv]*
//! *Compiler support: [requires `rustc` 1.50+][msrv]*
//!
//! [msrv]: #supported-rust-versions
//!
Expand Down Expand Up @@ -138,7 +138,7 @@
//! ## Supported Rust Versions
//!
//! Tracing is built against the latest stable release. The minimum supported
//! version is 1.49. The current Tracing version is not guaranteed to build on
//! version is 1.50. The current Tracing version is not guaranteed to build on
//! Rust versions earlier than the minimum supported version.
//!
//! Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down

0 comments on commit 605c2ef

Please sign in to comment.