Bug 16357: Only use Log4perl middleware if appenders defined

This patch checks that the loggers used by the middleware
actually have appenders defined.

Without this patch, if the loggers don't have appenders
defined in the log4perl file, the logs will just be lost.

Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
David Cook 2020-08-26 00:58:36 +00:00 committed by Jonathan Druart
parent 5651facf05
commit 68ec27562f
1 changed files with 13 additions and 6 deletions

View File

@ -38,6 +38,7 @@ use Koha::Database;
use Koha::DateUtils;
use Koha::Logger;
use Log::Log4perl;
use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise
{
no warnings 'redefine';
@ -77,18 +78,24 @@ builder {
enable "+Koha::Middleware::RealIP";
mount '/opac' => builder {
enable 'Log4perl', category => 'plack-opac';
enable 'LogWarn';
if ( Log::Log4perl->get_logger('plack-opac')->has_appenders ){
enable 'Log4perl', category => 'plack-opac';
enable 'LogWarn';
}
$opac;
};
mount '/intranet' => builder {
enable 'Log4perl', category => 'plack-intranet';
enable 'LogWarn';
if ( Log::Log4perl->get_logger('plack-intranet')->has_appenders ){
enable 'Log4perl', category => 'plack-intranet';
enable 'LogWarn';
}
$intranet;
};
mount '/api/v1/app.pl' => builder {
enable 'Log4perl', category => 'plack-api';
enable 'LogWarn';
if ( Log::Log4perl->get_logger('plack-api')->has_appenders ){
enable 'Log4perl', category => 'plack-api';
enable 'LogWarn';
}
$apiv1;
};
};