@@ -1284,11 +1284,30 @@ pub fn init_env_logger(env: &str) {
12841284 Ok ( s) if s. is_empty ( ) => return ,
12851285 Ok ( _) => { }
12861286 }
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+ } ;
12871306 let filter = tracing_subscriber:: EnvFilter :: from_env ( env) ;
12881307 let layer = tracing_tree:: HierarchicalLayer :: default ( )
12891308 . with_writer ( io:: stderr)
12901309 . with_indent_lines ( true )
1291- . with_ansi ( true )
1310+ . with_ansi ( color_logs )
12921311 . with_targets ( true )
12931312 . with_wraparound ( 10 )
12941313 . with_verbose_exit ( true )
@@ -1314,7 +1333,7 @@ pub fn main() -> ! {
13141333 arg. into_string ( ) . unwrap_or_else ( |arg| {
13151334 early_error (
13161335 ErrorOutputType :: default ( ) ,
1317- & format ! ( "Argument {} is not valid Unicode: {:?}" , i, arg) ,
1336+ & format ! ( "argument {} is not valid Unicode: {:?}" , i, arg) ,
13181337 )
13191338 } )
13201339 } )
0 commit comments