@@ -348,8 +348,11 @@ impl SimpleLogger {
348348 /// 'Init' the actual logger and instantiate it,
349349 /// this method MUST be called in order for the logger to be effective.
350350 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 ( ) ;
353356
354357 log:: set_max_level ( self . max_level ( ) ) ;
355358 log:: set_boxed_logger ( Box :: new ( self ) )
@@ -481,11 +484,12 @@ impl Log for SimpleLogger {
481484 fn flush ( & self ) { }
482485}
483486
484- /// Configure the console to display colours - Windows + colored
487+ /// Configure the console to display colours.
485488///
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.
487491#[ cfg( all( windows, feature = "colors" ) ) ]
488- pub fn set_up_color_terminal ( ) {
492+ pub fn set_up_windows_color_terminal ( ) {
489493 use std:: io:: { stdout, IsTerminal } ;
490494
491495 if stdout ( ) . is_terminal ( ) {
@@ -513,32 +517,15 @@ pub fn set_up_color_terminal() {
513517 }
514518}
515519
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 } ;
521525
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 ( ) ) ;
533527}
534528
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-
542529/// Initialise the logger with its default configuration.
543530///
544531/// Log messages will not be filtered.
0 commit comments