From bfa921665abfc4fcf8c5c3bc5f115769bf2c9f55 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 16 Apr 2020 16:11:02 +0200 Subject: [PATCH] Bug 25172: Make Koha::Logger explode if init went wrong We do not want to fail silently for the logger. Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/Logger.pm | 61 +++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/Koha/Logger.pm b/Koha/Logger.pm index dbcbd7c303..22f5fb6df6 100644 --- a/Koha/Logger.pm +++ b/Koha/Logger.pm @@ -112,59 +112,24 @@ sub AUTOLOAD { sub DESTROY { } -=head2 _init, _check_conf and _recheck_logfile +=head2 _init, _recheck_logfile =cut sub _init { - my $rv; - if ( exists $ENV{"LOG4PERL_CONF"} and $ENV{'LOG4PERL_CONF'} and -s $ENV{"LOG4PERL_CONF"} ) { - - # Check for web server level configuration first - # In this case we ASSUME that you correctly arranged logfile - # permissions. If not, log4perl will crash on you. - # We will not parse apache files here. - Log::Log4perl->init_once( $ENV{"LOG4PERL_CONF"} ); - } - elsif ( C4::Context->config("log4perl_conf") ) { - - # Now look in the koha conf file. We only check the permissions of - # the default logfiles. For the rest, we again ASSUME that - # you arranged file permissions. - my $conf = C4::Context->config("log4perl_conf"); - if ( $rv = _check_conf($conf) ) { - Log::Log4perl->init_once($conf); - return $rv; - } - else { - return 0; - } - } - else { - # This means that you do not use log4perl currently. - # We will not be forcing it. - return 0; - } - return 1; # if we make it here, log4perl did not crash :) -} -sub _check_conf { # check logfiles in log4perl config (at initialization) - my $file = shift; - return if !-r $file; - open my $fh, '<', $file; - my @lines = <$fh>; - close $fh; - my @logs; - foreach my $l (@lines) { - if ( $l =~ /(OPAC|INTRANET)\.filename\s*=\s*(.*)\s*$/i ) { - - # we only check the two default logfiles, skipping additional ones - return if !-w $2; - push @logs, $1 . ':' . $2; - } - } - return if !@logs; # we should find one - return \@logs; + my $log4perl_config = + exists $ENV{"LOG4PERL_CONF"} + && $ENV{'LOG4PERL_CONF'} + && -s $ENV{"LOG4PERL_CONF"} + # Check for web server level configuration first + # In this case we ASSUME that you correctly arranged logfile + # permissions. If not, log4perl will crash on you. + ? $ENV{"LOG4PERL_CONF"} + : C4::Context->config("log4perl_conf"); + + # This will explode with the relevant error message if something is wrong in the config file + return Log::Log4perl->init_once($log4perl_config); } sub _recheck_logfile { # recheck saved logfile when logging message -- 2.39.5