@@ -24,6 +24,7 @@ use rustc_feature::find_gated_cfg;
2424use rustc_interface:: util:: { self , collect_crate_types, get_codegen_backend} ;
2525use rustc_interface:: { interface, Queries } ;
2626use rustc_lint:: LintStore ;
27+ use rustc_log:: stdout_isatty;
2728use rustc_metadata:: locator;
2829use rustc_save_analysis as save;
2930use rustc_save_analysis:: DumpHandler ;
@@ -514,14 +515,6 @@ impl Compilation {
514515#[ derive( Copy , Clone ) ]
515516pub struct RustcDefaultCalls ;
516517
517- fn stdout_isatty ( ) -> bool {
518- atty:: is ( atty:: Stream :: Stdout )
519- }
520-
521- fn stderr_isatty ( ) -> bool {
522- atty:: is ( atty:: Stream :: Stderr )
523- }
524-
525518fn handle_explain ( registry : Registry , code : & str , output : ErrorOutputType ) {
526519 let upper_cased_code = code. to_ascii_uppercase ( ) ;
527520 let normalised = if upper_cased_code. starts_with ( 'E' ) {
@@ -1254,54 +1247,18 @@ pub fn install_ice_hook() {
12541247/// This allows tools to enable rust logging without having to magically match rustc's
12551248/// tracing crate version.
12561249pub fn init_rustc_env_logger ( ) {
1257- init_env_logger ( "RUSTC_LOG" )
1250+ if let Err ( error) = rustc_log:: init_rustc_env_logger ( ) {
1251+ early_error ( ErrorOutputType :: default ( ) , & error. to_string ( ) ) ;
1252+ }
12581253}
12591254
12601255/// This allows tools to enable rust logging without having to magically match rustc's
12611256/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var
12621257/// other than `RUSTC_LOG`.
12631258pub fn init_env_logger ( env : & str ) {
1264- use tracing_subscriber:: {
1265- filter:: { self , EnvFilter , LevelFilter } ,
1266- layer:: SubscriberExt ,
1267- } ;
1268-
1269- let filter = match std:: env:: var ( env) {
1270- Ok ( env) => EnvFilter :: new ( env) ,
1271- _ => EnvFilter :: default ( ) . add_directive ( filter:: Directive :: from ( LevelFilter :: WARN ) ) ,
1272- } ;
1273-
1274- let color_logs = match std:: env:: var ( String :: from ( env) + "_COLOR" ) {
1275- Ok ( value) => match value. as_ref ( ) {
1276- "always" => true ,
1277- "never" => false ,
1278- "auto" => stderr_isatty ( ) ,
1279- _ => early_error (
1280- ErrorOutputType :: default ( ) ,
1281- & format ! (
1282- "invalid log color value '{}': expected one of always, never, or auto" ,
1283- value
1284- ) ,
1285- ) ,
1286- } ,
1287- Err ( std:: env:: VarError :: NotPresent ) => stderr_isatty ( ) ,
1288- Err ( std:: env:: VarError :: NotUnicode ( _value) ) => early_error (
1289- ErrorOutputType :: default ( ) ,
1290- "non-Unicode log color value: expected one of always, never, or auto" ,
1291- ) ,
1292- } ;
1293-
1294- let layer = tracing_tree:: HierarchicalLayer :: default ( )
1295- . with_writer ( io:: stderr)
1296- . with_indent_lines ( true )
1297- . with_ansi ( color_logs)
1298- . with_targets ( true )
1299- . with_indent_amount ( 2 ) ;
1300- #[ cfg( parallel_compiler) ]
1301- let layer = layer. with_thread_ids ( true ) . with_thread_names ( true ) ;
1302-
1303- let subscriber = tracing_subscriber:: Registry :: default ( ) . with ( filter) . with ( layer) ;
1304- tracing:: subscriber:: set_global_default ( subscriber) . unwrap ( ) ;
1259+ if let Err ( error) = rustc_log:: init_env_logger ( env) {
1260+ early_error ( ErrorOutputType :: default ( ) , & error. to_string ( ) ) ;
1261+ }
13051262}
13061263
13071264#[ cfg( all( unix, any( target_env = "gnu" , target_os = "macos" ) ) ) ]
0 commit comments