Make Writer::with_ansi public #3287
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
I'm in the process of trying to work with
tracing_subscriber::fmt::Layer
in such a way that I can duplicate my console output from a command to a file. Specifically, I use a newtype wrapper alongsideLayer::map_event_format
to convert this output to HTML in conjunction with theansi-to-html
crate.It looks something like this:
The calling code for this looks something along the lines of:
However, because the default
Writer::new
implementation doesn't let you set whether or not ANSI codes can be output, I can't actually make aWriter
in myFormatEvent
impl that accepts ANSI output. As such, even though I'm converting viaansi_to_html
, theString
that intercepts the event formatter prior to conversion contains no ANSI codes.Solution
The solution is to just make
Writer::with_ansi
public:With this, all of the above works and I get colorized HTML output of the exact same log that goes to stderr.
cc @hawkw since there was a comment left behind to make this public.