From 44b8edad0fa458b483b1ad72056f0e69aebd433a Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 22 Jun 2020 03:53:16 +0000 Subject: [PATCH] Bug 16357: Override __WARN__ in Plack to use Log4Perl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch overrides __WARN__ in Plack to use Log4Perl to add timestamps to error output. The Log4Perl config uses a screen appender so the output still goes to STDERR so that it is still managed by Starman. This patch adds a Plack::Middleware::LogWarn package dependency. (The dependency is very simplistic, so we could always do out own version if we would prefer to skip the external dependency.) To Test: 0) apt-get install libplack-middleware-logwarn-perl 1) Apply patch 2) Copy PLACK block from etc/log4perl.conf to /etc/koha/sites/kohadev/log4perl.conf 3) Copy debian/templates/plack.psgi to /etc/koha/sites/kohadev/plack.psgi 4) Create some output on STDERR (it might be necessary to add a 'warn "TEST";' line to the intranet or OPAC) 5) koha-plack --restart kohadev 6) Open /var/log/koha/kohadev/plack-error.log 7) Observe a log line like the following: [2020/06/22 03:51:23] [WARN] TEST at /kohadevbox/koha/opac/opac-user.pl line 59. Signed-off-by: Arthur Suzuki Signed-off-by: Joonas Kylmälä --- debian/control | 2 ++ debian/templates/log4perl-site.conf.in | 8 ++++++++ debian/templates/plack.psgi | 5 +++++ etc/log4perl.conf | 8 ++++++++ 4 files changed, 23 insertions(+) diff --git a/debian/control b/debian/control index 7dcbd1d54c..4c926a1104 100644 --- a/debian/control +++ b/debian/control @@ -111,6 +111,7 @@ Build-Depends: libalgorithm-checkdigits-perl, libpdf-reuse-barcode-perl, libpdf-reuse-perl, libpdf-table-perl, + libplack-middleware-logwarn-perl, libplack-middleware-reverseproxy-perl, libppi-perl, libreadonly-perl, @@ -346,6 +347,7 @@ Depends: libalgorithm-checkdigits-perl, libpdf-reuse-barcode-perl, libpdf-reuse-perl, libpdf-table-perl, + libplack-middleware-logwarn-perl, libplack-middleware-reverseproxy-perl, libppi-perl, libreadonly-perl, diff --git a/debian/templates/log4perl-site.conf.in b/debian/templates/log4perl-site.conf.in index df61c9a9ec..b893241559 100644 --- a/debian/templates/log4perl-site.conf.in +++ b/debian/templates/log4perl-site.conf.in @@ -37,3 +37,11 @@ log4perl.appender.SIP.mode=append log4perl.appender.SIP.layout=PatternLayout log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %m %l %n log4perl.appender.SIP.utf8=1 + +log4perl.logger.plack = WARN, PLACK +log4perl.appender.PLACK=Log::Log4perl::Appender::Screen +log4perl.appender.PLACK.stderr = 1 +log4perl.appender.PLACK.mode=append +log4perl.appender.PLACK.layout=PatternLayout +log4perl.appender.PLACK.layout.ConversionPattern=[%d] [%p] %m +log4perl.appender.PLACK.utf8=1 diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index cde680ee30..c06ff4b913 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -36,6 +36,7 @@ use Koha::Caches; use Koha::Cache::Memory::Lite; use Koha::Database; use Koha::DateUtils; +use Koha::Logger; use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise { @@ -65,9 +66,13 @@ my $apiv1 = builder { $server->to_psgi_app; }; +Koha::Logger->get; + builder { enable "ReverseProxy"; enable "Plack::Middleware::Static"; + enable "Log4perl", category => "plack"; + enable "LogWarn"; # + is required so Plack doesn't try to prefix Plack::Middleware:: enable "+Koha::Middleware::SetEnv"; diff --git a/etc/log4perl.conf b/etc/log4perl.conf index df61c9a9ec..b893241559 100644 --- a/etc/log4perl.conf +++ b/etc/log4perl.conf @@ -37,3 +37,11 @@ log4perl.appender.SIP.mode=append log4perl.appender.SIP.layout=PatternLayout log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %m %l %n log4perl.appender.SIP.utf8=1 + +log4perl.logger.plack = WARN, PLACK +log4perl.appender.PLACK=Log::Log4perl::Appender::Screen +log4perl.appender.PLACK.stderr = 1 +log4perl.appender.PLACK.mode=append +log4perl.appender.PLACK.layout=PatternLayout +log4perl.appender.PLACK.layout.ConversionPattern=[%d] [%p] %m +log4perl.appender.PLACK.utf8=1 -- 2.11.0