Open
Conversation
Author
|
I forgot to search before I pushed this, so I see #2806 as well. I would be happy to close my PR and get either merged. |
Author
|
To note: I think I can also make this work by overriding the writer settings for ANSI by doing: So perhaps this isn't necessary. That additional Perhaps I should just close this so as to not add one more spot where you can get this wrong... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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::Layerin 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_formatto convert this output to HTML in conjunction with theansi-to-htmlcrate.It looks something like this:
The calling code for this looks something along the lines of:
However, because the default
Writer::newimplementation doesn't let you set whether or not ANSI codes can be output, I can't actually make aWriterin myFormatEventimpl that accepts ANSI output. As such, even though I'm converting viaansi_to_html, theStringthat intercepts the event formatter prior to conversion contains no ANSI codes.Solution
The solution is to just make
Writer::with_ansipublic: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.