Skip to content

Commit 733828c

Browse files
ematipicosiketyanmdevils
authored
fix(cli): logging color (#7441)
Co-authored-by: siketyan <[email protected]> Co-authored-by: mdevils <[email protected]>
1 parent 9686f98 commit 733828c

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

.changeset/shy-ants-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#3824](https://github.com/biomejs/biome/issues/3824). Now the option CLI `--color` is correctly applied to logging too.

crates/biome_cli/src/cli_options.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ pub enum ColorsArg {
118118
Force,
119119
}
120120

121+
impl ColorsArg {
122+
pub fn is_enabled(&self) -> bool {
123+
matches!(self, Self::Force)
124+
}
125+
pub fn is_disabled(&self) -> bool {
126+
matches!(self, Self::Off)
127+
}
128+
}
129+
121130
impl FromStr for ColorsArg {
122131
type Err = String;
123132

crates/biome_cli/src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ pub(crate) trait CommandRunner: Sized {
850850
cli_options.log_file.as_deref(),
851851
cli_options.log_level,
852852
cli_options.log_kind,
853+
cli_options.colors.as_ref(),
853854
);
854855
let console = &mut *session.app.console;
855856
let workspace = &*session.app.workspace;

crates/biome_cli/src/logging.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fmt::{Display, Formatter};
22
use std::fs::File;
33
use std::str::FromStr;
44

5+
use crate::cli_options::ColorsArg;
56
use tracing::Metadata;
67
use tracing::subscriber::Interest;
78
use tracing_subscriber::filter::LevelFilter;
@@ -10,7 +11,12 @@ use tracing_subscriber::layer::{Context, Filter, SubscriberExt};
1011
use tracing_subscriber::util::SubscriberInitExt;
1112
use tracing_subscriber::{Layer as _, registry};
1213

13-
pub fn setup_cli_subscriber(file: Option<&str>, level: LoggingLevel, kind: LoggingKind) {
14+
pub fn setup_cli_subscriber(
15+
file: Option<&str>,
16+
level: LoggingLevel,
17+
kind: LoggingKind,
18+
colors: Option<&ColorsArg>,
19+
) {
1420
if level == LoggingLevel::None {
1521
return;
1622
}
@@ -20,7 +26,7 @@ pub fn setup_cli_subscriber(file: Option<&str>, level: LoggingLevel, kind: Loggi
2026
.with_target(false)
2127
.with_thread_names(true)
2228
.with_file(true)
23-
.with_ansi(true);
29+
.with_ansi(colors.is_none_or(|c| c.is_enabled()));
2430

2531
if level == LoggingLevel::Tracing {
2632
format = format.with_span_events(FmtSpan::CLOSE);

0 commit comments

Comments
 (0)