From 53919b6013c797f3a38f17accfbd9a168b425f28 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Thu, 12 May 2016 19:50:22 +0300 Subject: [PATCH] Bug 16509 - Koha::Logger dies when log4perl.conf has FileAppender files with different owners, also compatibility with logrotate We define all the logging configurations for various interfaces in log4perl.conf. Interfaces log to files, and every interface can run as a different user. Every time you execute a Perl program that uses Koha::Logger and Log::Log4perl, Log::Log4perl tries to open all the filehandles in the log4perl.conf. Since different interface logs should be owned by different users, this crashes the system: Can't sysopen /home/koha/koha-dev/var/log/intranet.log (Permission denied) at /usr/local/share/perl/5.18.2/Log/Log4perl/Appender/File.pm line 120. This patch introduces lazy-loading parameters to the FileAppenders, so they open only the files they need. Koha::Logger makes sure they always use the correct log file for the interface (opac, intranet, commandline, sip, restapi, ...). log4perl.appender.CLI.syswrite=true log4perl.appender.*.create_at_logtime=true Also while working on this bug identified as a target of opportunity some useful extra parameters for the appenders. log4perl.appender.*.syswrite=true This should solve concurrency issues under multithreaded Perl-apps such as what Mojolicious should be ran as. log4perl.appender.*.recreate=true This polls the filesystem path to the logfile for changes. Eg. if logrotate or the admin might move the logfile for storage purposes, Log4perl can recreate the missing file, instead of writing to the moved file. --- etc/log4perl.conf | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/etc/log4perl.conf b/etc/log4perl.conf index c63a8db..54f6238 100644 --- a/etc/log4perl.conf +++ b/etc/log4perl.conf @@ -1,6 +1,9 @@ log4perl.logger.intranet = WARN, INTRANET log4perl.appender.INTRANET=Log::Log4perl::Appender::File log4perl.appender.INTRANET.filename=__LOG_DIR__/intranet.log +log4perl.appender.INTRANET.create_at_logtime=true +log4perl.appender.INTRANET.syswrite=true +log4perl.appender.INTRANET.recreate=true log4perl.appender.INTRANET.mode=append log4perl.appender.INTRANET.layout=PatternLayout log4perl.appender.INTRANET.layout.ConversionPattern=[%d] [%p] %m %l %n @@ -8,6 +11,9 @@ log4perl.appender.INTRANET.layout.ConversionPattern=[%d] [%p] %m %l %n log4perl.logger.opac = WARN, OPAC log4perl.appender.OPAC=Log::Log4perl::Appender::File log4perl.appender.OPAC.filename=__LOG_DIR__/opac.log +log4perl.appender.OPAC.create_at_logtime=true +log4perl.appender.OPAC.syswrite=true +log4perl.appender.OPAC.recreate=true log4perl.appender.OPAC.mode=append log4perl.appender.OPAC.layout=PatternLayout log4perl.appender.OPAC.layout.ConversionPattern=[%d] [%p] %m %l %n @@ -15,6 +21,9 @@ log4perl.appender.OPAC.layout.ConversionPattern=[%d] [%p] %m %l %n log4perl.logger.commandline = WARN, CLI log4perl.appender.CLI=Log::Log4perl::Appender::File log4perl.appender.CLI.filename=__LOG_DIR__/cli.log +log4perl.appender.CLI.create_at_logtime=true +log4perl.appender.CLI.syswrite=true +log4perl.appender.CLI.recreate=true log4perl.appender.CLI.mode=append log4perl.appender.CLI.layout=PatternLayout -log4perl.appender.CLI.layout.ConversionPattern=[%d] [%p] %m %l %n \ No newline at end of file +log4perl.appender.CLI.layout.ConversionPattern=[%d] [%p] %m %l %n -- 1.9.1