From 08ea39aa19bd04f4b971a424b3d789de95527d49 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Thu, 3 Jan 2013 12:45:38 +0100
Subject: [PATCH] Bug 8190: QA Followup

- Remove the private variables
- Remove the use of C4::Context in the UT
- Remove the Exporter

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 C4/Context.pm        |    1 -
 Koha/Utils/Logger.pm |   56 ++++++++++++++++----------------------------------
 opac/opac-search.pl  |    4 ++--
 t/Logger.t           |    9 ++------
 4 files changed, 22 insertions(+), 48 deletions(-)

diff --git a/C4/Context.pm b/C4/Context.pm
index 2eb5e3c..d4a40d6 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -1251,7 +1251,6 @@ this method creates one, and caches it.
 sub logger
 {
     my $self = shift;
-    my $sth;
 
     if ( defined( $context->{"logger"} ) ) {
         return $context->{"logger"};
diff --git a/Koha/Utils/Logger.pm b/Koha/Utils/Logger.pm
index e8c0b91..c7b4680 100644
--- a/Koha/Utils/Logger.pm
+++ b/Koha/Utils/Logger.pm
@@ -3,44 +3,15 @@ package Koha::Utils::Logger;
 use Modern::Perl;
 use Log::LogLite;
 
-use base 'Exporter';
-our @EXPORT_OK = qw($log);
-
-my $UNUSABLE_LOG_LEVEL = 1;
-my $CRITICAL_LOG_LEVEL = 2;
-my $ERROR_LOG_LEVEL    = 3;
-my $WARNING_LOG_LEVEL  = 4;
-my $NORMAL_LOG_LEVEL   = 5;
-my $INFO_LOG_LEVEL     = 6;
-my $DEBUG_LOG_LEVEL    = 7;
-
-my $LEVEL_STR = {
-    $UNUSABLE_LOG_LEVEL => 'UNUS  ',
-    $CRITICAL_LOG_LEVEL => 'CRIT  ',
-    $ERROR_LOG_LEVEL    => 'ERROR ',
-    $WARNING_LOG_LEVEL  => 'WARN  ',
-    $NORMAL_LOG_LEVEL   => 'NORMAL',
-    $INFO_LOG_LEVEL     => 'INFO  ',
-    $DEBUG_LOG_LEVEL    => 'DEBUG ',
-};
-
 use Data::Dumper;
 
-our $log = undef;
-
 sub new {
     my ( $proto, $params ) = @_;
-
-    return $log
-      if $log
-          and (  not defined $params->{file}
-              or not defined $log->{FILE_PATH}
-              or $params->{file} eq $log->{FILE_PATH} );
     my $class    = ref($proto) || $proto;
     my $self     = {};
     my $LOG_PATH = defined $ENV{KOHA_LOG} ? $ENV{KOHA_LOG} : undef;
     $self->{FILE_PATH} = defined $params->{file}  ? $params->{file}  : $LOG_PATH;
-    $self->{LEVEL}     = defined $params->{level} ? $params->{level} : $INFO_LOG_LEVEL;
+    $self->{LEVEL}     = defined $params->{level} ? $params->{level} : 5;
     $self->{LOGGED_MESSAGES} = [];
 
     if ( not defined $self->{FILE_PATH} ) {
@@ -54,6 +25,15 @@ sub new {
 sub _write {
     my ( $self, $msg, $log_level, $dump, $cb ) = @_;
 
+    my $LEVEL_STR = {
+        1 => 'UNUS  ',
+        2 => 'CRIT  ',
+        3 => 'ERROR ',
+        4 => 'WARN  ',
+        5 => 'NORMAL',
+        6 => 'INFO  ',
+        7 => 'DEBUG ',
+    };
     if ( not $self->{LOGGER} ) {
         if ( $log_level <= $self->{LEVEL} ) {
             print STDERR "[" . localtime() . "] " . "$LEVEL_STR->{$log_level}: " . $msg . ( $cb ? " (" . $cb . ")" : "" ) . "\n";
@@ -76,45 +56,45 @@ sub _write {
 sub unusable {
     my ( $self, $msg, $dump ) = @_;
     my $cb = $self->_called_by();
-    $self->_write( $msg, $UNUSABLE_LOG_LEVEL, $dump, $cb );
+    $self->_write( $msg, 1, $dump, $cb );
 }
 
 sub critical {
     my ( $self, $msg, $dump ) = @_;
     my $cb = $self->_called_by();
-    $self->_write( $msg, $CRITICAL_LOG_LEVEL, $dump, $cb );
+    $self->_write( $msg, 2, $dump, $cb );
 }
 
 sub error {
     my ( $self, $msg, $dump ) = @_;
     my $cb = $self->_called_by();
-    $self->_write( $msg, $ERROR_LOG_LEVEL, $dump, $cb );
+    $self->_write( $msg, 3, $dump, $cb );
 }
 
 sub warning {
     my ( $self, $msg, $dump ) = @_;
     my $cb = $self->_called_by();
-    $self->_write( $msg, $WARNING_LOG_LEVEL, $dump, $cb );
+    $self->_write( $msg, 4, $dump, $cb );
 }
 
 sub log {
     my ( $self, $msg, $dump ) = @_;
-    $self->_write( $msg, $NORMAL_LOG_LEVEL, $dump );
+    $self->_write( $msg, 5, $dump );
 }
 
 sub normal {
     my ( $self, $msg, $dump ) = @_;
-    $self->_write( $msg, $NORMAL_LOG_LEVEL, $dump );
+    $self->_write( $msg, 5, $dump );
 }
 
 sub info {
     my ( $self, $msg, $dump ) = @_;
-    $self->_write( $msg, $INFO_LOG_LEVEL, $dump );
+    $self->_write( $msg, 6, $dump );
 }
 
 sub debug {
     my ( $self, $msg, $dump ) = @_;
-    $self->_write( $msg, $DEBUG_LOG_LEVEL, $dump );
+    $self->_write( $msg, 7, $dump );
 }
 
 sub level {
diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 8bd040f..66171e0 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -51,14 +51,14 @@ use C4::Tags qw(get_tags);
 use C4::Branch; # GetBranches
 use C4::SocialData;
 use C4::Ratings;
-use Koha::Utils::Logger qw/$log/;
+use Koha::Utils::Logger;
 
 use POSIX qw(ceil floor strftime);
 use URI::Escape;
 use Storable qw(thaw freeze);
 use Business::ISBN;
 
-$log = Koha::Utils::Logger->new({level => C4::Context->preference("LogLevel")});
+my $log = Koha::Utils::Logger->new({level => C4::Context->preference("LogLevel")});
 
 my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
 # create a new CGI object
diff --git a/t/Logger.t b/t/Logger.t
index 1e42180..6ee3f0b 100644
--- a/t/Logger.t
+++ b/t/Logger.t
@@ -4,19 +4,14 @@ use utf8;
 use Modern::Perl;
 
 use Test::More;
-require C4::Context;
-import C4::Context;
-plan tests => 15;
+plan tests => 13;
 
 $ENV{KOHA_LOG} = q{/tmp/logger.log};
 
 my $logfile = $ENV{KOHA_LOG};
 
 use_ok('Koha::Utils::Logger');
-isnt(C4::Context->preference("LogLevel"), undef, "Check LogLevel syspref");
-use Koha::Utils::Logger qw/$log/;
-is($log, undef, "Check \$log is undef");
-$log = Koha::Utils::Logger->new({level => 3});
+my $log = Koha::Utils::Logger->new({level => 3});
 isnt($log, undef, "Check \$log is not undef");
 
 
-- 
1.7.10.4