-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: make ANSI and not-ANSI formatting consistent
Currently, the `tracing-subscriber` crate's `fmt` module has two separate `fmt::Display` impls for its' `FmtCtx` and `FullCtx` types, depending on whether the feature flag that enables ANSI colors is set. Since a lot of the `fmt::Display` implementations doesn't have anything to do with ANSI colors, this means that we have a lot of repeated code, and in order to keep the formatting consistent, we have to keep these implementations in sync manually. There are currently some inconsistencies in formatting with ANSI colors on and off, implying that we have failed to do that. This commit simplifies the situation significantly by consolidating the `fmt::Display` impls into one implementation, and only feature flagging the code that actually needs to be different. We do this by introducing a `Style` type which exposes no-op versions of methods with the same names as the `ansi-term` crate's `Style` when ANSI formatting is disabled. Now, the conditional logic is hidden in the function that returns a `Style`, and the rest of the `fmt::Display` implementations can be agnostic of ANSI colors. In release mode, `rustc` should be able to optimize out the no-op methods and empty struct entirely. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
- Loading branch information
Showing
1 changed file
with
34 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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