@@ -1284,11 +1284,30 @@ pub fn init_env_logger(env: &str) {
1284
1284
Ok ( s) if s. is_empty ( ) => return ,
1285
1285
Ok ( _) => { }
1286
1286
}
1287
+ let color_logs = match std:: env:: var ( String :: from ( env) + "_COLOR" ) {
1288
+ Ok ( value) => match value. as_ref ( ) {
1289
+ "always" => true ,
1290
+ "never" => false ,
1291
+ "auto" => stdout_isatty ( ) ,
1292
+ _ => early_error (
1293
+ ErrorOutputType :: default ( ) ,
1294
+ & format ! (
1295
+ "invalid log color value '{}': expected one of always, never, or auto" ,
1296
+ value
1297
+ ) ,
1298
+ ) ,
1299
+ } ,
1300
+ Err ( std:: env:: VarError :: NotPresent ) => stdout_isatty ( ) ,
1301
+ Err ( std:: env:: VarError :: NotUnicode ( _value) ) => early_error (
1302
+ ErrorOutputType :: default ( ) ,
1303
+ "non-Unicode log color value: expected one of always, never, or auto" ,
1304
+ ) ,
1305
+ } ;
1287
1306
let filter = tracing_subscriber:: EnvFilter :: from_env ( env) ;
1288
1307
let layer = tracing_tree:: HierarchicalLayer :: default ( )
1289
1308
. with_writer ( io:: stderr)
1290
1309
. with_indent_lines ( true )
1291
- . with_ansi ( true )
1310
+ . with_ansi ( color_logs )
1292
1311
. with_targets ( true )
1293
1312
. with_wraparound ( 10 )
1294
1313
. with_verbose_exit ( true )
@@ -1314,7 +1333,7 @@ pub fn main() -> ! {
1314
1333
arg. into_string ( ) . unwrap_or_else ( |arg| {
1315
1334
early_error (
1316
1335
ErrorOutputType :: default ( ) ,
1317
- & format ! ( "Argument {} is not valid Unicode: {:?}" , i, arg) ,
1336
+ & format ! ( "argument {} is not valid Unicode: {:?}" , i, arg) ,
1318
1337
)
1319
1338
} )
1320
1339
} )
0 commit comments