Skip to content

subscriber: Change Writer's with_ansi* accessors to pub#3554

Open
bminortx wants to merge 1 commit into
tokio-rs:mainfrom
bminortx:writer-ansi
Open

subscriber: Change Writer's with_ansi* accessors to pub#3554
bminortx wants to merge 1 commit into
tokio-rs:mainfrom
bminortx:writer-ansi

Conversation

@bminortx

Copy link
Copy Markdown

This PR changes the scope of the with_ansi* accessors in the Writer class from pub(crate) to pub.

Motivation

Our software's workflow maps a subscriber's events to a Writer class for writing stdout and stderr to an HTML file. While the subscriber layer itself can set with_ansi_sanitization to false (thereby giving us "clean" output), the writer instead holds its own state. This caused some confusion when the Writer ended up writing codes, when the output to the console did not.

let report_layer = tracing_subscriber::fmt::layer()
                .with_target(print_target)
                .with_writer(report_writer)
                .pretty()
                .with_ansi(true)
                .map_event_format(move |e| {
                    let f = e
                        .with_ansi(true)
                        .with_source_location(print_source_location);
                    FormatHtml::new(f, converter) // <-- This holds a Writer
                })
                .with_ansi_sanitization(false);   // <-- which makes this useless in the Writer context

Solution

Make the accessors public so that we can modify the Writer behavior to match the layer from which it is mapped. Happy to hear other solutions, but given the discussion in the file, it seems like this may have been on your minds anyway.

@bminortx bminortx requested review from a team, hawkw and hds as code owners May 29, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant