Browse Source

Bug 16357: Override __WARN__ in Plack to use Log4Perl

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 <arthur.suzuki@biblibre.com>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
David Cook 2 years ago
committed by Jonathan Druart
parent
commit
57c62a612d
  1. 2
      debian/control
  2. 8
      debian/templates/log4perl-site.conf.in
  3. 5
      debian/templates/plack.psgi
  4. 8
      etc/log4perl.conf

2
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,

8
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

5
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";

8
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

Loading…
Cancel
Save