From 0f34dece1bd2e20f93a02eb09daf17eff371521b Mon Sep 17 00:00:00 2001 From: ageorge95 Date: Tue, 27 Oct 2026 21:04:10 +0200 Subject: [PATCH] subspace-process: disable console colors in both 0.15 and 0.16 Substrate still links against console 0.15.x while the workspace uses console 0.16.x. Each version keeps its own global color state, so disabling colors only in 0.16 left Substrate's console-styled log messages colored. tracing-subscriber then escaped those embedded ANSI codes into literal `\x1b[` text. Depend on console 0.15.11 in subspace-process and disable colors in both versions during init_logger. Extend the regression test to cover the 0.15 path used by Substrate. --- Cargo.lock | 1 + shared/subspace-process/Cargo.toml | 4 ++++ shared/subspace-process/src/lib.rs | 6 ++++++ shared/subspace-process/src/tests.rs | 10 +++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index fec6825450..2d44167d11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15295,6 +15295,7 @@ dependencies = [ name = "subspace-process" version = "0.0.1" dependencies = [ + "console 0.15.11", "console 0.16.6", "fdlimit", "futures", diff --git a/shared/subspace-process/Cargo.toml b/shared/subspace-process/Cargo.toml index bf959ab44a..a266c87c73 100644 --- a/shared/subspace-process/Cargo.toml +++ b/shared/subspace-process/Cargo.toml @@ -11,7 +11,11 @@ include = [ ] [dependencies] +# Substrate crates (and therefore their `console`-styled log messages) still link +# against console 0.15.x, whose color state is independent of console 0.16.x. +# Depend on both so `init_logger` can disable colors in each version's global state. console.workspace = true +console-0-15 = { package = "console", version = "0.15.11" } fdlimit.workspace = true futures.workspace = true supports-color.workspace = true diff --git a/shared/subspace-process/src/lib.rs b/shared/subspace-process/src/lib.rs index d9839a0441..0cdc81101a 100644 --- a/shared/subspace-process/src/lib.rs +++ b/shared/subspace-process/src/lib.rs @@ -23,8 +23,14 @@ pub fn init_logger() { // sc_informant and other substrate crates colorize log content via `console`; // tracing-subscriber 0.3.20+ escapes those embedded ANSI codes into literal `\x1b[` // text in the message. Turn console color off at the source so nothing is emitted. + // + // The workspace uses console 0.16.x, but substrate still links against console + // 0.15.x, which keeps its own global color state. Disable colors in both so the + // workaround remains effective for substrate's messages. console::set_colors_enabled(false); console::set_colors_enabled_stderr(false); + console_0_15::set_colors_enabled(false); + console_0_15::set_colors_enabled_stderr(false); // TODO: Workaround for https://github.com/tokio-rs/tracing/issues/2214, also on // Windows terminal doesn't support the same colors as bash does diff --git a/shared/subspace-process/src/tests.rs b/shared/subspace-process/src/tests.rs index a967faa63b..ec682788d6 100644 --- a/shared/subspace-process/src/tests.rs +++ b/shared/subspace-process/src/tests.rs @@ -13,7 +13,15 @@ fn init_logger_disables_console_ansi() { let styled = format!("{}", console::style("x").white().bold()); assert_eq!( styled, "x", - "console emitted ANSI after init_logger: {styled:?}" + "console 0.16 emitted ANSI after init_logger: {styled:?}" + ); + + // Substrate still links against console 0.15.x; ensure its global color state is + // disabled too. + let styled_legacy = format!("{}", console_0_15::style("x").white().bold()); + assert_eq!( + styled_legacy, "x", + "console 0.15 emitted ANSI after init_logger: {styled_legacy:?}" ); }