From 462fff3463e484da4f4bb32e125c6d318c5b6dc1 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 11 Jan 2023 18:46:11 +0000 Subject: [PATCH] Bug 32612: Add worker-error to log4perl conf To test: 1 - Apply patch 2 - vim /etc/koha/sites/kohadev/log4perl.conf, Add lines below: log4perl.logger.worker = WARN, WORKER log4perl.appender.WORKER=Log::Log4perl::Appender::Screen log4perl.appender.WORKER.stderr=1 log4perl.appender.WORKER.mode=append log4perl.appender.WORKER.layout=PatternLayout log4perl.appender.WORKER.layout.ConversionPattern=[%d] [%p] %m %l%n log4perl.appender.WORKER.utf8=1 3 - Restart all 4 - Edit misc/background_jobs_worker.pl - my $job = Koha::BackgroundJobs->find($args->{job_id}); + my $job;# = Koha::BackgroundJobs->find($args->{job_id}); 5 - In another terminal: tail -f /var/log/koha/kohadev/koha-worker-error.log 6 - Force enqueue a job (that won't be found because of #4 perl -e 'use Koha::BackgroundJob::BatchUpdateItem; my $bg = Koha::BackgroundJob::BatchUpdateItem->new(); $bg->enqueue({ record_ids=>['888888']});' 7 - Note error in log like: [2023/01/11 19:26:10] [WARN] No job found for id=2983 main:: /kohadevbox/koha/misc/background_jobs_worker.pl (111) --- debian/koha-common.postinst | 16 ++++++++++++++++ etc/log4perl.conf | 8 ++++++++ misc/background_jobs_worker.pl | 4 ++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/debian/koha-common.postinst b/debian/koha-common.postinst index 2540ea654f..8d50f556fb 100644 --- a/debian/koha-common.postinst +++ b/debian/koha-common.postinst @@ -267,4 +267,20 @@ service rabbitmq-server restart update-rc.d koha-common disable update-rc.d koha-common enable +for site in $(koha-list); do + log4perl_config="/etc/koha/sites/$site/log4perl.conf" + if ! log4perl_component $log4perl_config "worker"; then + cat <> $log4perl_config +log4perl.logger.worker = WARN, WORKER +log4perl.appender.WORKER=Log::Log4perl::Appender::Screen +log4perl.appender.WORKER.stderr=1 +log4perl.appender.WORKER.mode=append +log4perl.appender.WORKER.layout=PatternLayout +log4perl.appender.WORKER.layout.ConversionPattern=[%d] [%p] %m %l%n +log4perl.appender.WORKER.utf8=1 + +EOF + fi +done + exit 0 diff --git a/etc/log4perl.conf b/etc/log4perl.conf index a07d139d96..a1252dec66 100644 --- a/etc/log4perl.conf +++ b/etc/log4perl.conf @@ -14,6 +14,14 @@ log4perl.appender.OPAC.layout=PatternLayout log4perl.appender.OPAC.layout.ConversionPattern=[%d] [%p] %m %l%n log4perl.appender.OPAC.utf8=1 +log4perl.logger.worker = WARN, WORKER +log4perl.appender.WORKER=Log::Log4perl::Appender::Screen +log4perl.appender.WORKER.stderr=1 +log4perl.appender.WORKER.mode=append +log4perl.appender.WORKER.layout=PatternLayout +log4perl.appender.WORKER.layout.ConversionPattern=[%d] [%p] %m %l%n +log4perl.appender.WORKER.utf8=1 + log4perl.logger.z3950 = WARN, Z3950 log4perl.appender.Z3950=Log::Log4perl::Appender::File log4perl.appender.Z3950.filename=__LOG_DIR__/z3950-error.log diff --git a/misc/background_jobs_worker.pl b/misc/background_jobs_worker.pl index a9a037ed76..829e48726e 100755 --- a/misc/background_jobs_worker.pl +++ b/misc/background_jobs_worker.pl @@ -98,7 +98,7 @@ while (1) { my $body = $frame->body; decode_json($body); # TODO Should this be from_json? Check utf8 flag. } catch { - Koha::Logger->get->warn(sprintf "Frame not processed - %s", $_); + Koha::Logger->get({ interface => 'worker' })->warn(sprintf "Frame not processed - %s", $_); return; } finally { $conn->ack( { frame => $frame } ); @@ -111,7 +111,7 @@ while (1) { my $job = Koha::BackgroundJobs->find($args->{job_id}); unless ( $job ) { - Koha::Logger->get->warn(sprintf "No job found for id=%s", $args->{job_id}); + Koha::Logger->get({ interface => 'worker' })->warn(sprintf "No job found for id=%s", $args->{job_id}); next; } -- 2.30.2