@@ -348,8 +348,11 @@ impl SimpleLogger {
348
348
/// 'Init' the actual logger and instantiate it,
349
349
/// this method MUST be called in order for the logger to be effective.
350
350
pub fn init ( self ) -> Result < ( ) , SetLoggerError > {
351
- // Setup colors if needed. The implementation if feature dependent.
352
- set_up_color_terminal ( ) ;
351
+ #[ cfg( all( windows, feature = "colored" ) ) ]
352
+ set_up_windows_color_terminal ( ) ;
353
+
354
+ #[ cfg( all( feature = "colored" , feature = "stderr" ) ) ]
355
+ use_stderr_for_colors ( ) ;
353
356
354
357
log:: set_max_level ( self . max_level ( ) ) ;
355
358
log:: set_boxed_logger ( Box :: new ( self ) )
@@ -481,11 +484,12 @@ impl Log for SimpleLogger {
481
484
fn flush ( & self ) { }
482
485
}
483
486
484
- /// Configure the console to display colours - Windows + colored
487
+ /// Configure the console to display colours.
485
488
///
486
- /// This is only needed on Windows when using the 'colored' feature.
489
+ /// This is only needed on Windows when using the 'colors' feature.
490
+ /// It doesn't currently handle combining the 'colors' and 'stderr' features.
487
491
#[ cfg( all( windows, feature = "colors" ) ) ]
488
- pub fn set_up_color_terminal ( ) {
492
+ pub fn set_up_windows_color_terminal ( ) {
489
493
use std:: io:: { stdout, IsTerminal } ;
490
494
491
495
if stdout ( ) . is_terminal ( ) {
@@ -513,32 +517,15 @@ pub fn set_up_color_terminal() {
513
517
}
514
518
}
515
519
516
- /// Configure the console to display colours - Windows + !colored
517
- ///
518
- /// This method does nothing if running on Windows with the colored feature disabled.
519
- # [ cfg ( all ( windows , not ( feature = "colors" ) ) ) ]
520
- pub fn set_up_color_terminal ( ) { }
520
+ /// The colored crate will disable colors when STDOUT is not a terminal. This method overrides this
521
+ /// behaviour to check the status of STDERR instead.
522
+ # [ cfg ( all ( feature = " colored" , feature = "stderr" ) ) ]
523
+ fn use_stderr_for_colors ( ) {
524
+ use std :: io :: { stderr , IsTerminal } ;
521
525
522
- /// Configure the console to display colours - !Windows + stderr + colors
523
- ///
524
- /// The colored crate will disable colors when stdout is not a terminal. This method overrides this
525
- /// behaviour to check the status of stderr instead.
526
- #[ cfg( all( not( windows) , feature = "stderr" ) ) ]
527
- pub fn set_up_color_terminal ( ) {
528
- #[ cfg( feature = "colors" ) ]
529
- {
530
- use std:: io:: { stderr, IsTerminal } ;
531
- colored:: control:: set_override ( stderr ( ) . is_terminal ( ) ) ;
532
- }
526
+ colored:: control:: set_override ( stderr ( ) . is_terminal ( ) ) ;
533
527
}
534
528
535
- /// Configure the console to display colours - !Windows + !stderr
536
- ///
537
- /// This method does nothing if not running on Windows with the colored feature and outputting on
538
- /// stdout.
539
- #[ cfg( all( not( windows) , not( feature = "stderr" ) ) ) ]
540
- pub fn set_up_color_terminal ( ) { }
541
-
542
529
/// Initialise the logger with its default configuration.
543
530
///
544
531
/// Log messages will not be filtered.
0 commit comments