[Rt-commit] rt branch, 4.4/use-logger-for-config-warnings, created. rt-4.4.2-117-g121e899eb

Jim Brandt jbrandt at bestpractical.com
Thu Apr 5 11:36:20 EDT 2018


The branch, 4.4/use-logger-for-config-warnings has been created
        at  121e899eb86c810bc5aaa96803b5e6d60ad1623e (commit)

- Log -----------------------------------------------------------------
commit d9175d1c0d12e1a9efd074da0aaecfaf23234030
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Apr 5 11:28:43 2018 -0400

    Store log messages until RT::Logger is initialized
    
    Log messages generated during startup configuration processing
    can't use RT::Logger because it hasn't been initialized yet.
    Store them and output the messages as soon as the logger is
    available. This allows the log messages to be output in the context
    of the configured log level, so debug messages won't be output
    if RT is configured to show only warn or error.

diff --git a/lib/RT.pm b/lib/RT.pm
index e14211c71..bd4cbc0e6 100644
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -200,6 +200,7 @@ sub Init {
     InitSystemObjects();
     InitClasses(%args);
     InitLogging();
+    ProcessPreInitMessages();
     InitPlugins();
     _BuildTableAttributes();
     RT::I18N->Init;
@@ -374,6 +375,15 @@ sub InitLogging {
     InitSignalHandlers();
 }
 
+# Some messages may have been logged before the logger was available.
+# Output them here.
+
+sub ProcessPreInitMessages {
+    foreach my $message ( @RT::Config::PreInitLoggerMessages ){
+        RT->Logger->debug($message);
+    }
+}
+
 sub InitSignalHandlers {
 
 # Signal handlers
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index d03b78d4c..d122c8fa3 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -57,6 +57,9 @@ use Symbol::Global::Name;
 use List::MoreUtils 'uniq';
 use Storable ();
 
+# Store log messages generated before RT::Logger is available
+our @PreInitLoggerMessages;
+
 =head1 NAME
 
     RT::Config - RT's config
@@ -1635,7 +1638,7 @@ sub SetFromConfig {
             # override options that came from its main config
             if ( $args{'Extension'} ne $META{$name}->{'Source'}{'Extension'} ) {
                 my %source = %{ $META{$name}->{'Source'} };
-                warn
+                push @PreInitLoggerMessages,
                     "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
                     ." This option earlier has been set in $source{'File'} line $source{'Line'}."
                     ." To overide this option use ". ($source{'Extension'}||'RT')
@@ -1652,7 +1655,7 @@ sub SetFromConfig {
                 # as a site config is loaded earlier then its base config
                 # then we warn only on different extensions, for example
                 # RTIR's options is set in main site config
-                warn
+                push @PreInitLoggerMessages,
                     "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
                     ." It may be ok, but we want you to be aware."
                     ." This option has been set earlier in $source{'File'} line $source{'Line'}."

commit 121e899eb86c810bc5aaa96803b5e6d60ad1623e
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Thu Apr 5 11:33:21 2018 -0400

    Use RT::Logger for EmailInputEncodings config warnings

diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index d122c8fa3..84132ce77 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -990,7 +990,7 @@ our %META;
 
                 my $canonic = Encode::resolve_alias( $encoding );
                 unless ( $canonic ) {
-                    warn "Unknown encoding '$encoding' in \@EmailInputEncodings option";
+                    $RT::Logger->warning("Unknown encoding '$encoding' in \@EmailInputEncodings option");
                 }
                 elsif ( $seen{ $canonic }++ ) {
                     next;
diff --git a/t/api/config.t b/t/api/config.t
index b87531139..34b68d72a 100644
--- a/t/api/config.t
+++ b/t/api/config.t
@@ -36,7 +36,7 @@ is( RT::Config->Meta('foo'), undef, 'foo is indeed deleted' );
 RT::Config->Set('EmailInputEncodings', qw(utf-8 iso-8859-1 us-ascii foo));
 my @encodings = qw(utf-8-strict iso-8859-1 ascii);
 
-warning_is {RT::Config->PostLoadCheck} "Unknown encoding 'foo' in \@EmailInputEncodings option",
+warning_like {RT::Config->PostLoadCheck} qr{Unknown encoding \'foo\' in \@EmailInputEncodings option},
   'Correct warning for encoding foo';
 
 RT::Config->Set( WebDefaultStylesheet => 'non-existent-skin-name' );

-----------------------------------------------------------------------


More information about the rt-commit mailing list