Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/stackable-telemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Fixed

- Only use ANSI escape sequences if stdout is a terminal/tty. Piping the output to a file will now
result in plain text log messages ([#1183]).

[#1183]: https://github.com/stackabletech/operator-rs/pull/1183

## [0.6.2] - 2026-03-09

### Fixed
Expand Down
12 changes: 9 additions & 3 deletions crates/stackable-telemetry/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! To get started, see [`Tracing`].

use std::{ops::Not, path::PathBuf};
use std::{io::IsTerminal, ops::Not, path::PathBuf};

use opentelemetry::trace::TracerProvider;
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
Expand Down Expand Up @@ -432,15 +432,21 @@ impl Tracing {

// NOTE (@NickLarsenNZ): There is no elegant way to build the layer depending on formats because the types
// returned from each subscriber "modifier" function is different (sometimes with different generics).
// tracing-subscriber does not auto-detect whether stdout is a terminal
// (https://github.com/tokio-rs/tracing/issues/1160), so we check explicitly.
let use_ansi = std::io::stdout().is_terminal();

match log_format {
Format::Plain => {
let console_output_layer =
tracing_subscriber::fmt::layer().with_filter(env_filter_layer);
let console_output_layer = tracing_subscriber::fmt::layer()
.with_ansi(use_ansi)
.with_filter(env_filter_layer);
layers.push(console_output_layer.boxed());
}
Format::Json => {
let console_output_layer = tracing_subscriber::fmt::layer()
.json()
.with_ansi(use_ansi)
.with_filter(env_filter_layer);
layers.push(console_output_layer.boxed());
}
Expand Down
Loading