From fa84c17cfdc325b6756611c8eef8b26ef96e101e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 28 Sep 2015 10:18:15 +0100 Subject: [PATCH] Bug 14906: Koha::Logger - handle permission issues Koha::Logger should log in the regular log files if the paths are not correctly set (does not exist, no permission to write, etc.). Test plan: Set a path without write permission for the intranet in the log4perl configuration file. The one for opac should be correct. Try to write 1 line in the OPAC file. Without this patch, nothing is logged, and nothing is warned in the regular Koha log file. With this patch, the line in the OPAC log file will be appened and the Koha log file will have a line with a permission issue. --- Koha/Logger.pm | 5 ++++- t/Logger.t | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Koha/Logger.pm b/Koha/Logger.pm index b454100..04eaa02 100644 --- a/Koha/Logger.pm +++ b/Koha/Logger.pm @@ -155,7 +155,10 @@ sub _check_conf { # check logfiles in log4perl config (at initialization) if ( $l =~ /(OPAC|INTRANET)\.filename\s*=\s*(.*)\s*$/i ) { # we only check the two default logfiles, skipping additional ones - return if !-w $2; + unless ( -w $2 ) { + carp "Logger configuration error - Wrong permission for file $2"; + next; + } push @logs, $1 . ':' . $2; } } diff --git a/t/Logger.t b/t/Logger.t index cef4ea1..43001c6 100644 --- a/t/Logger.t +++ b/t/Logger.t @@ -26,7 +26,7 @@ use Test::More tests => 1; use Test::Warn; subtest 'Test01 -- Simple tests for Koha::Logger' => sub { - plan tests => 8; + plan tests => 9; test01(); }; @@ -52,7 +52,12 @@ log4perl.appender.INTRANET.layout.ConversionPattern=[%d] [%p] %m %l %n HERE ); $mContext->mock( 'config', sub { return $conf; } ); - $logger= Koha::Logger->get({ interface => 'intranet' }); + system("chmod 400 $log"); + warning_like { $logger = Koha::Logger->get({ interface => 'intranet' }) } + qr/permission/, "Koha::Logger should raise a warning if there is a permission issue"; + + system("chmod 600 $log"); + $logger = Koha::Logger->get({ interface => 'intranet' }); is( exists $logger->{logger}, 1, 'Log4perl config found'); is( $logger->warn('Message 2'), 1, 'Message 2 returned a value' ); warning_is { $ret = $logger->catastrophe } -- 2.1.0