From c8dd361a36e79923d3121044c6ccdf611761fa51 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 29 Aug 2022 09:58:38 +0000 Subject: [PATCH] Bug 22678: Replace a few unneeded Koha::Logger calls We have Koha::Logger via the Mojo app now. Test plan: Run perl t/db_dependent/api/v1/unhandled_exceptions.t Your plack-api-error.log should contain something like: [2022/08/29 12:15:25] [ERROR] DELETE /api/v1/patrons/1052: unhandled exception (Koha::Exception)<> Bonus: Add one line to Koha/REST/Plugin/PluginRoutes.pm: $app->log->error('PluginRoutes L49'); Before the line with if ( C4::Context->config("enable_plugins") ) Restart and hit the API once again. Your log should contain: [2022/08/29 12:21:55] [ERROR] PluginRoutes L49 This serves to demonstrate that the $api->log change in PluginRoutes works. Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/REST/Plugin/Exceptions.pm | 4 +--- Koha/REST/Plugin/PluginRoutes.pm | 8 +++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Koha/REST/Plugin/Exceptions.pm b/Koha/REST/Plugin/Exceptions.pm index b069711596..fd28d67e7f 100644 --- a/Koha/REST/Plugin/Exceptions.pm +++ b/Koha/REST/Plugin/Exceptions.pm @@ -18,7 +18,6 @@ package Koha::REST::Plugin::Exceptions; use Modern::Perl; use Scalar::Util qw( blessed ); -use Koha::Logger; use Mojo::Base 'Mojolicious::Plugin'; @@ -69,8 +68,7 @@ sub register { my $message = "$method $path: unhandled exception $type\<\<$exception_string\>\>"; - my $logger = Koha::Logger->get({ interface => 'api' }); - $logger->error("$message"); + $c->app->log->error( "$message" ); $c->render( status => 500, diff --git a/Koha/REST/Plugin/PluginRoutes.pm b/Koha/REST/Plugin/PluginRoutes.pm index e626a179b8..c275f2578c 100644 --- a/Koha/REST/Plugin/PluginRoutes.pm +++ b/Koha/REST/Plugin/PluginRoutes.pm @@ -21,7 +21,6 @@ use Mojo::Base 'Mojolicious::Plugin'; use Koha::Exceptions::Plugin; use Koha::Plugins; -use Koha::Logger; use Clone qw( clone ); use JSON::Validator::Schema::OpenAPIv2; @@ -57,7 +56,7 @@ sub register { ); foreach my $plugin ( @plugins ) { - $spec = $self->inject_routes( $spec, $plugin, $validate ); + $spec = $self->inject_routes( $spec, $plugin, $validate, $app->log ); } } @@ -70,7 +69,7 @@ sub register { =cut sub inject_routes { - my ( $self, $spec, $plugin, $validate ) = @_; + my ( $self, $spec, $plugin, $validate, $logger ) = @_; return merge_spec( $spec, $plugin ) unless $validate; @@ -91,8 +90,7 @@ sub inject_routes { catch { my $error = $_; my $class = ref $plugin; - my $logger = Koha::Logger->get({ interface => 'api' }); - $logger->error("Plugin $class route injection failed: $error"); + $logger->error( "Plugin $class route injection failed: $error" ); return $spec; }; } -- 2.39.5