@@ -142,11 +142,24 @@ pub(crate) fn setup_logging(
142
142
. from_env ( )
143
143
. context ( "Invalid RUST_LOG directives" ) ?;
144
144
145
- let ansi = match color. and_colorchoice ( anstream:: Stderr :: choice ( & std:: io:: stderr ( ) ) ) {
146
- ColorChoice :: Always => true ,
147
- ColorChoice :: Never => false ,
148
- ColorChoice :: Auto => unreachable ! ( "anstream can't return auto as choice" ) ,
149
- } ;
145
+ // Determine our final color settings and create an anstream wrapper based on it.
146
+ //
147
+ // The tracing `with_ansi` function on affects color tracing adds *on top of* the
148
+ // log messages. This means that if we `debug!("{}", "hello".green())`,
149
+ // (a thing we absolutely do throughout uv), then there will still be color
150
+ // in the logs, which is undesirable.
151
+ //
152
+ // So we tell tracing to print to an anstream wrapper around stderr that force-strips ansi.
153
+ // Given we do this, using `with_ansi` at all is arguably pointless, but it feels morally
154
+ // correct to still do it? I don't know what would break if we didn't... but why find out?
155
+ let ( ansi, color_choice) =
156
+ match color. and_colorchoice ( anstream:: Stderr :: choice ( & std:: io:: stderr ( ) ) ) {
157
+ ColorChoice :: Always => ( true , anstream:: ColorChoice :: Always ) ,
158
+ ColorChoice :: Never => ( false , anstream:: ColorChoice :: Never ) ,
159
+ ColorChoice :: Auto => unreachable ! ( "anstream can't return auto as choice" ) ,
160
+ } ;
161
+ let writer = std:: sync:: Mutex :: new ( anstream:: AutoStream :: new ( std:: io:: stderr ( ) , color_choice) ) ;
162
+
150
163
match level {
151
164
Level :: Default | Level :: Verbose => {
152
165
// Regardless of the tracing level, show messages without any adornment.
@@ -161,7 +174,7 @@ pub(crate) fn setup_logging(
161
174
. with (
162
175
tracing_subscriber:: fmt:: layer ( )
163
176
. event_format ( format)
164
- . with_writer ( std :: io :: stderr )
177
+ . with_writer ( writer )
165
178
. with_ansi ( ansi)
166
179
. with_filter ( filter) ,
167
180
)
@@ -175,7 +188,7 @@ pub(crate) fn setup_logging(
175
188
HierarchicalLayer :: default ( )
176
189
. with_targets ( true )
177
190
. with_timer ( Uptime :: default ( ) )
178
- . with_writer ( std :: io :: stderr )
191
+ . with_writer ( writer )
179
192
. with_ansi ( ansi)
180
193
. with_filter ( filter) ,
181
194
)
0 commit comments