From 869f120e23fbaeb01523e644abf761b7714ca817 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Wed, 28 Mar 2018 15:01:32 -0400 Subject: [PATCH] Bug 16357 - Use Koha::Logger via Plack::Middleware::Log4perl Changes plack.psgi to use the Koha::Logger via Plack::Middleware::Log4perl. Changes the log category to 'plack' to be more similar to the existing categories --- debian/templates/log4perl-site.conf.in | 7 +++++++ debian/templates/plack.psgi | 12 +++++------- etc/log4perl.conf | 12 ++++++------ misc/plack/koha.psgi | 14 +++++++------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/debian/templates/log4perl-site.conf.in b/debian/templates/log4perl-site.conf.in index efc4707..91df7d6 100644 --- a/debian/templates/log4perl-site.conf.in +++ b/debian/templates/log4perl-site.conf.in @@ -11,3 +11,10 @@ log4perl.appender.OPAC.filename=__LOG_DIR__/opac-error.log log4perl.appender.OPAC.mode=append log4perl.appender.OPAC.layout=PatternLayout log4perl.appender.OPAC.layout.ConversionPattern=[%d] [%p] %m %l %n + +log4perl.logger.plack = WARN, PLACK +log4perl.appender.PLACK=Log::Log4perl::Appender::File +log4perl.appender.PLACK.filename=__LOG_DIR__/plack-error.log +log4perl.appender.PLACK.mode=append +log4perl.appender.PLACK.layout=PatternLayout +log4perl.appender.PLACK.layout.ConversionPattern=[%d] [%p] %m diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index 2c65dc7..778befd 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -36,14 +36,8 @@ use Koha::Caches; use Koha::Cache::Memory::Lite; use Koha::Database; use Koha::DateUtils; - -#BZ 16357, add timestamps to warnings use Koha::Logger; -my $logger = Koha::Logger->get({ interface => 'plack-error' }); -$SIG{__WARN__} = sub { $logger->warn(shift); }; -$SIG{__DIE__} = sub { $logger->fatal(shift); }; - use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise { no warnings 'redefine'; @@ -72,14 +66,18 @@ my $apiv1 = builder { $server->to_psgi_app; }; +Koha::Logger->get; + builder { enable "ReverseProxy"; enable "Plack::Middleware::Static"; + enable "Log4perl", category => "plack"; + enable "LogErrors"; + enable "LogWarn"; # + is required so Plack doesn't try to prefix Plack::Middleware:: enable "+Koha::Middleware::SetEnv"; mount '/opac' => $opac; mount '/intranet' => $intranet; mount '/api/v1/app.pl' => $apiv1; - }; diff --git a/etc/log4perl.conf b/etc/log4perl.conf index bcf8159..91df7d6 100644 --- a/etc/log4perl.conf +++ b/etc/log4perl.conf @@ -12,9 +12,9 @@ log4perl.appender.OPAC.mode=append log4perl.appender.OPAC.layout=PatternLayout log4perl.appender.OPAC.layout.ConversionPattern=[%d] [%p] %m %l %n -log4perl.logger.plack-error = WARN, PLACK-ERROR -log4perl.appender.PLACK-ERROR=Log::Log4perl::Appender::File -log4perl.appender.PLACK-ERROR.filename=__LOG_DIR__/plack-error.log -log4perl.appender.PLACK-ERROR.mode=append -log4perl.appender.PLACK-ERROR.layout=PatternLayout -log4perl.appender.PLACK-ERROR.layout.ConversionPattern=[%d] [%p] %m +log4perl.logger.plack = WARN, PLACK +log4perl.appender.PLACK=Log::Log4perl::Appender::File +log4perl.appender.PLACK.filename=__LOG_DIR__/plack-error.log +log4perl.appender.PLACK.mode=append +log4perl.appender.PLACK.layout=PatternLayout +log4perl.appender.PLACK.layout.ConversionPattern=[%d] [%p] %m diff --git a/misc/plack/koha.psgi b/misc/plack/koha.psgi index a7989f5..e6fa5e1 100644 --- a/misc/plack/koha.psgi +++ b/misc/plack/koha.psgi @@ -5,13 +5,6 @@ use lib qw( ./lib ); use Plack::Middleware::Debug; use Plack::App::Directory; -#BZ 16357, add timestamps to warnings -use Koha::Logger; - -my $logger = Koha::Logger->get({ interface => 'plack-error' }); -$SIG{__WARN__} = sub { $logger->warn(shift); }; -$SIG{__DIE__} = sub { $logger->fatal(shift); }; - use CGI qw(-utf8 ); # we will lose -utf8 under plack { no warnings 'redefine'; @@ -54,6 +47,7 @@ use Koha::DateUtils; use Koha::Caches; use Koha::Cache::Memory::Lite; use Koha::Patron::Categories; +use Koha::Logger; =for preload use C4::Tags; # FIXME @@ -79,6 +73,8 @@ my $home = sub { return [ 302, [ Location => '/cgi-bin/koha/' . ( $ENV{INTRANET} ? 'mainpage.pl' : 'opac-main.pl' ) ] ]; }; +Koha::Logger->get; + builder { # please don't use plugins which are under enable_if $ENV{PLACK_DEBUG} in production! @@ -102,6 +98,10 @@ builder { path => qr{^/(intranet|opac)-tmpl/}, root => "$ENV{INTRANETDIR}/koha-tmpl/"; + enable "Log4perl", category => "plack"; + enable "LogErrors"; + enable "LogWarn"; + # + is required so Plack doesn't try to prefix Plack::Middleware:: enable "+Koha::Middleware::SetEnv"; -- 2.7.4