@@ -24,6 +24,7 @@ use rustc_feature::find_gated_cfg;
24
24
use rustc_interface:: util:: { self , collect_crate_types, get_codegen_backend} ;
25
25
use rustc_interface:: { interface, Queries } ;
26
26
use rustc_lint:: LintStore ;
27
+ use rustc_log:: stdout_isatty;
27
28
use rustc_metadata:: locator;
28
29
use rustc_save_analysis as save;
29
30
use rustc_save_analysis:: DumpHandler ;
@@ -514,14 +515,6 @@ impl Compilation {
514
515
#[ derive( Copy , Clone ) ]
515
516
pub struct RustcDefaultCalls ;
516
517
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
-
525
518
fn handle_explain ( registry : Registry , code : & str , output : ErrorOutputType ) {
526
519
let upper_cased_code = code. to_ascii_uppercase ( ) ;
527
520
let normalised = if upper_cased_code. starts_with ( 'E' ) {
@@ -1254,54 +1247,18 @@ pub fn install_ice_hook() {
1254
1247
/// This allows tools to enable rust logging without having to magically match rustc's
1255
1248
/// tracing crate version.
1256
1249
pub 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
+ }
1258
1253
}
1259
1254
1260
1255
/// This allows tools to enable rust logging without having to magically match rustc's
1261
1256
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var
1262
1257
/// other than `RUSTC_LOG`.
1263
1258
pub 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
+ }
1305
1262
}
1306
1263
1307
1264
#[ cfg( all( unix, any( target_env = "gnu" , target_os = "macos" ) ) ) ]
0 commit comments