Skip to content

Commit a42e963

Browse files
poliorceticshawkw
authored andcommitted
subscriber: replace unmaintained ansi_term with nu-ansi-term (#2287)
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
1 parent a4fc92c commit a42e963

File tree

9 files changed

+64
-76
lines changed

9 files changed

+64
-76
lines changed

.github/workflows/CI.yml

+32-44
Original file line numberDiff line numberDiff line change
@@ -179,50 +179,38 @@ jobs:
179179
name: "cargo check (MSRV on ubuntu-latest)"
180180
needs: check
181181
runs-on: ubuntu-latest
182-
steps:
183-
- uses: actions/checkout@v3
184-
- name: "install Rust ${{ env.MSRV }}"
185-
uses: actions-rs/toolchain@v1
186-
with:
187-
toolchain: ${{ env.MSRV }}
188-
profile: minimal
189-
- name: "install Rust nightly"
190-
uses: actions-rs/toolchain@v1
191-
with:
192-
toolchain: nightly
193-
profile: minimal
194-
- name: Select minimal versions
195-
uses: actions-rs/cargo@v1
196-
with:
197-
command: update
198-
args: -Z minimal-versions
199-
toolchain: nightly
200-
- name: Check
201-
uses: actions-rs/cargo@v1
202-
with:
203-
command: check
204-
# skip the following crates:
205-
# - tracing-appender, as it has its own MSRV.
206-
# TODO(eliza): remove this when appender is on the same MSRV as
207-
# everything else
208-
# - the examples, as they are not published & we don't care about
209-
# MSRV support for them.
210-
# - tracing-futures, as it depends on ancient tokio versions.
211-
# TODO(eliza): remove this when the ancient tokio deps are dropped
212-
args: >-
213-
--workspace --all-features --locked
214-
--exclude=tracing-appender
215-
--exclude=tracing-examples
216-
--exclude=tracing-futures
217-
--exclude=tracing-opentelemetry
218-
toolchain: ${{ env.MSRV }}
219-
220-
# TODO: remove this once tracing's MSRV is bumped.
221-
check-msrv-appender:
222-
# Run `cargo check` on our minimum supported Rust version (1.53.0).
223-
name: "cargo check (tracing-appender MSRV)"
224-
needs: check
225-
runs-on: ubuntu-latest
182+
strategy:
183+
matrix:
184+
# cargo hack --feature-powerset will have a significant permutation
185+
# number, we can't just use --all as it increases the runtime
186+
# further than what we would like to
187+
subcrate:
188+
- tracing-appender
189+
- tracing-attributes
190+
- tracing-core
191+
- tracing-futures
192+
- tracing-log
193+
- tracing-macros
194+
- tracing-serde
195+
- tracing-subscriber
196+
- tracing-tower
197+
- tracing-opentelemetry
198+
- tracing
199+
toolchain:
200+
- 1.49.0
201+
- stable
202+
# TODO(eliza): remove this when appender is on the same MSRV.
203+
# same for tracing subscriber
204+
exclude:
205+
- subcrate: tracing-appender
206+
toolchain: 1.49.0
207+
- subcrate: tracing-subscriber
208+
toolchain: 1.49.0
209+
include:
210+
- subcrate: tracing-appender
211+
toolchain: 1.53.0
212+
- subcrate: tracing-subscriber
213+
toolchain: 1.50.0
226214
steps:
227215
- uses: actions/checkout@v3
228216
- name: "install Rust ${{ env.APPENDER_MSRV }}"

examples/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bytes = "1"
4343
argh = "0.1.8"
4444

4545
# sloggish example
46-
ansi_term = "0.12.1"
46+
nu-ansi-term = "0.46.0"
4747
humantime = "2.1.0"
4848
log = "0.4.17"
4949

examples/examples/sloggish/sloggish_subscriber.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//!
1111
//! [`slog-term`]: https://docs.rs/slog-term/2.4.0/slog_term/
1212
//! [`slog` README]: https://github.com/slog-rs/slog#terminal-output-example
13-
use ansi_term::{Color, Style};
13+
use nu_ansi_term::{Color, Style};
1414
use tracing::{
1515
field::{Field, Visit},
1616
Id, Level, Subscriber,
@@ -129,7 +129,7 @@ impl<'a> Visit for Event<'a> {
129129
write!(
130130
&mut self.stderr,
131131
"{}",
132-
// Have to alloc here due to `ansi_term`'s API...
132+
// Have to alloc here due to `nu_ansi_term`'s API...
133133
Style::new().bold().paint(format!("{:?}", value))
134134
)
135135
.unwrap();

tracing-subscriber/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ categories = [
2020
"asynchronous",
2121
]
2222
keywords = ["logging", "tracing", "metrics", "subscriber"]
23-
rust-version = "1.49.0"
23+
rust-version = "1.50.0"
2424

2525
[features]
2626

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

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

5555
# only required by the json feature

tracing-subscriber/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ Utilities for implementing and composing [`tracing`][tracing] subscribers.
3232
[discord-url]: https://discord.gg/EeF3cQw
3333
[maint-badge]: https://img.shields.io/badge/maintenance-experimental-blue.svg
3434

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

3737
[msrv]: #supported-rust-versions
3838

3939
## Supported Rust Versions
4040

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

4545
Tracing follows the same compiler support policies as the rest of the Tokio

tracing-subscriber/src/filter/env/builder.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ impl Builder {
209209
}
210210

211211
if !disabled.is_empty() {
212-
#[cfg(feature = "ansi_term")]
213-
use ansi_term::{Color, Style};
212+
#[cfg(feature = "nu_ansi_term")]
213+
use nu_ansi_term::{Color, Style};
214214
// NOTE: We can't use a configured `MakeWriter` because the EnvFilter
215215
// has no knowledge of any underlying subscriber or collector, which
216216
// may or may not use a `MakeWriter`.
217217
let warn = |msg: &str| {
218-
#[cfg(not(feature = "ansi_term"))]
218+
#[cfg(not(feature = "nu_ansi_term"))]
219219
let msg = format!("warning: {}", msg);
220-
#[cfg(feature = "ansi_term")]
220+
#[cfg(feature = "nu_ansi_term")]
221221
let msg = {
222222
let bold = Style::new().bold();
223223
let mut warning = Color::Yellow.paint("warning");
@@ -227,9 +227,9 @@ impl Builder {
227227
eprintln!("{}", msg);
228228
};
229229
let ctx_prefixed = |prefix: &str, msg: &str| {
230-
#[cfg(not(feature = "ansi_term"))]
230+
#[cfg(not(feature = "nu_ansi_term"))]
231231
let msg = format!("{} {}", prefix, msg);
232-
#[cfg(feature = "ansi_term")]
232+
#[cfg(feature = "nu_ansi_term")]
233233
let msg = {
234234
let mut equal = Color::Fixed(21).paint("="); // dark blue
235235
equal.style_ref_mut().is_bold = true;
@@ -240,9 +240,9 @@ impl Builder {
240240
let ctx_help = |msg| ctx_prefixed("help:", msg);
241241
let ctx_note = |msg| ctx_prefixed("note:", msg);
242242
let ctx = |msg: &str| {
243-
#[cfg(not(feature = "ansi_term"))]
243+
#[cfg(not(feature = "nu_ansi_term"))]
244244
let msg = format!("note: {}", msg);
245-
#[cfg(feature = "ansi_term")]
245+
#[cfg(feature = "nu_ansi_term")]
246246
let msg = {
247247
let mut pipe = Color::Fixed(21).paint("|");
248248
pipe.style_ref_mut().is_bold = true;

tracing-subscriber/src/fmt/format/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use tracing_core::{
4646
use tracing_log::NormalizeEvent;
4747

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

5151
#[cfg(feature = "json")]
5252
mod json;
@@ -101,7 +101,7 @@ pub use pretty::*;
101101
/// does not support ANSI escape codes (such as a log file), and they should
102102
/// not be emitted.
103103
///
104-
/// Crates like [`ansi_term`] and [`owo-colors`] can be used to add ANSI
104+
/// Crates like [`nu_ansi_term`] and [`owo-colors`] can be used to add ANSI
105105
/// escape codes to formatted output.
106106
///
107107
/// * The actual [`Event`] to be formatted.
@@ -189,7 +189,7 @@ pub use pretty::*;
189189
/// [implements `FormatFields`]: super::FmtContext#impl-FormatFields<'writer>
190190
/// [ANSI terminal escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code
191191
/// [`Writer::has_ansi_escapes`]: Writer::has_ansi_escapes
192-
/// [`ansi_term`]: https://crates.io/crates/ansi_term
192+
/// [`nu_ansi_term`]: https://crates.io/crates/nu_ansi_term
193193
/// [`owo-colors`]: https://crates.io/crates/owo-colors
194194
/// [default formatter]: Full
195195
pub trait FormatEvent<S, N>
@@ -1484,11 +1484,11 @@ impl<'a> fmt::Display for FmtLevel<'a> {
14841484
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14851485
if self.ansi {
14861486
match *self.level {
1487-
Level::TRACE => write!(f, "{}", Colour::Purple.paint(TRACE_STR)),
1488-
Level::DEBUG => write!(f, "{}", Colour::Blue.paint(DEBUG_STR)),
1489-
Level::INFO => write!(f, "{}", Colour::Green.paint(INFO_STR)),
1490-
Level::WARN => write!(f, "{}", Colour::Yellow.paint(WARN_STR)),
1491-
Level::ERROR => write!(f, "{}", Colour::Red.paint(ERROR_STR)),
1487+
Level::TRACE => write!(f, "{}", Color::Purple.paint(TRACE_STR)),
1488+
Level::DEBUG => write!(f, "{}", Color::Blue.paint(DEBUG_STR)),
1489+
Level::INFO => write!(f, "{}", Color::Green.paint(INFO_STR)),
1490+
Level::WARN => write!(f, "{}", Color::Yellow.paint(WARN_STR)),
1491+
Level::ERROR => write!(f, "{}", Color::Red.paint(ERROR_STR)),
14921492
}
14931493
} else {
14941494
match *self.level {

tracing-subscriber/src/fmt/format/pretty.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tracing_core::{
1414
#[cfg(feature = "tracing-log")]
1515
use tracing_log::NormalizeEvent;
1616

17-
use ansi_term::{Colour, Style};
17+
use nu_ansi_term::{Color, Style};
1818

1919
/// An excessively pretty, human-readable event formatter.
2020
///
@@ -143,11 +143,11 @@ impl Default for Pretty {
143143
impl Pretty {
144144
fn style_for(level: &Level) -> Style {
145145
match *level {
146-
Level::TRACE => Style::new().fg(Colour::Purple),
147-
Level::DEBUG => Style::new().fg(Colour::Blue),
148-
Level::INFO => Style::new().fg(Colour::Green),
149-
Level::WARN => Style::new().fg(Colour::Yellow),
150-
Level::ERROR => Style::new().fg(Colour::Red),
146+
Level::TRACE => Style::new().fg(Color::Purple),
147+
Level::DEBUG => Style::new().fg(Color::Blue),
148+
Level::INFO => Style::new().fg(Color::Green),
149+
Level::WARN => Style::new().fg(Color::Yellow),
150+
Level::ERROR => Style::new().fg(Color::Red),
151151
}
152152
}
153153

tracing-subscriber/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! `tracing-subscriber` is intended for use by both `Subscriber` authors and
1111
//! application authors using `tracing` to instrument their applications.
1212
//!
13-
//! *Compiler support: [requires `rustc` 1.49+][msrv]*
13+
//! *Compiler support: [requires `rustc` 1.50+][msrv]*
1414
//!
1515
//! [msrv]: #supported-rust-versions
1616
//!
@@ -138,7 +138,7 @@
138138
//! ## Supported Rust Versions
139139
//!
140140
//! Tracing is built against the latest stable release. The minimum supported
141-
//! version is 1.49. The current Tracing version is not guaranteed to build on
141+
//! version is 1.50. The current Tracing version is not guaranteed to build on
142142
//! Rust versions earlier than the minimum supported version.
143143
//!
144144
//! Tracing follows the same compiler support policies as the rest of the Tokio

0 commit comments

Comments
 (0)