From c2f1a41670f52835d1d0b00f12eb8faebc2ad636 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 13 Jul 2023 14:23:22 +0000 Subject: [PATCH] Bug 34271: Remove a few Logger statements from REST API See also bug 22678. We should call app->log->warn, ->debug, etc. instead of Logger. Test plan: The simplest way I tested V1, is add a app->log->warn in the try blocks, restart all and check that your log4perl is set correctly too. Signed-off-by: Marcel de Rooy Signed-off-by: David Cook Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit a3ce05012b8a2ee6b47c82d14f61c082798ab8a1) Signed-off-by: Fridolin Somers --- Koha/REST/V1.pm | 8 +++----- Koha/REST/V1/OAuth/Client.pm | 7 ++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Koha/REST/V1.pm b/Koha/REST/V1.pm index cfb7a597f4..59f8f88e34 100644 --- a/Koha/REST/V1.pm +++ b/Koha/REST/V1.pm @@ -109,8 +109,7 @@ sub startup { # to catch bad ones. # JSON::Validator uses confess, so trim call stack from the message. - my $logger = Koha::Logger->get({ interface => 'api' }); - $logger->error("Warning: Could not load REST API spec bundle: " . $_); + $self->app->log->error("Warning: Could not load REST API spec bundle: " . $_); try { @@ -135,7 +134,7 @@ sub startup { } catch { # JSON::Validator uses confess, so trim call stack from the message. - $logger->error("Warning: Could not load REST API spec bundle: " . $_); + $self->app->log->error("Warning: Could not load REST API spec bundle: " . $_); }; }; @@ -148,8 +147,7 @@ sub startup { $oauth_configuration->{ $provider->code } = decode_json( $provider->config ); } } catch { - my $logger = Koha::Logger->get( { interface => 'api' } ); - $logger->warn( "Warning: Failed to fetch oauth configuration: " . $_ ); + $self->app->log->warn( "Warning: Failed to fetch oauth configuration: " . $_ ); }; $self->plugin( 'Koha::REST::Plugin::Pagination' ); diff --git a/Koha/REST/V1/OAuth/Client.pm b/Koha/REST/V1/OAuth/Client.pm index b6f66b022c..ad15a87967 100644 --- a/Koha/REST/V1/OAuth/Client.pm +++ b/Koha/REST/V1/OAuth/Client.pm @@ -23,7 +23,6 @@ use Mojo::Base 'Mojolicious::Controller'; use Mojo::URL; use Scalar::Util qw(blessed); use Try::Tiny; -use Koha::Logger; use Koha::Token; use URI::Escape qw(uri_escape_utf8); @@ -47,8 +46,6 @@ sub login { my $provider = $c->param('provider_code'); my $interface = $c->param('interface'); - my $logger = Koha::Logger->get({ interface => 'api' }); - my $provider_config = $c->oauth2->providers->{$provider}; my $uri; @@ -132,7 +129,7 @@ sub login { $c->redirect_to($uri); } catch { my $error = $_; - $logger->error($error); + $c->app->log->error($error); # TODO: Review behavior if ( blessed $error ) { if ( $error->isa('Koha::Exceptions::Auth::Unauthorized') ) { @@ -151,7 +148,7 @@ sub login { )->catch( sub { my $error = shift; - $logger->error($error); + $c->app->log->error($error); $error = uri_escape_utf8($error); $c->redirect_to($uri."?auth_error=$error"); } -- 2.39.2