View | Details | Raw Unified | Return to bug 8190
Collapse All | Expand All

(-)a/C4/Context.pm (-1 lines)
Lines 1206-1212 this method creates one, and caches it. Link Here
1206
sub logger
1206
sub logger
1207
{
1207
{
1208
    my $self = shift;
1208
    my $self = shift;
1209
    my $sth;
1210
1209
1211
    if ( defined( $context->{"logger"} ) ) {
1210
    if ( defined( $context->{"logger"} ) ) {
1212
        return $context->{"logger"};
1211
        return $context->{"logger"};
(-)a/Koha/Utils/Logger.pm (-38 / +18 lines)
Lines 3-46 package Koha::Utils::Logger; Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use Log::LogLite;
4
use Log::LogLite;
5
5
6
use base 'Exporter';
7
our @EXPORT_OK = qw($log);
8
9
my $UNUSABLE_LOG_LEVEL = 1;
10
my $CRITICAL_LOG_LEVEL = 2;
11
my $ERROR_LOG_LEVEL    = 3;
12
my $WARNING_LOG_LEVEL  = 4;
13
my $NORMAL_LOG_LEVEL   = 5;
14
my $INFO_LOG_LEVEL     = 6;
15
my $DEBUG_LOG_LEVEL    = 7;
16
17
my $LEVEL_STR = {
18
    $UNUSABLE_LOG_LEVEL => 'UNUS  ',
19
    $CRITICAL_LOG_LEVEL => 'CRIT  ',
20
    $ERROR_LOG_LEVEL    => 'ERROR ',
21
    $WARNING_LOG_LEVEL  => 'WARN  ',
22
    $NORMAL_LOG_LEVEL   => 'NORMAL',
23
    $INFO_LOG_LEVEL     => 'INFO  ',
24
    $DEBUG_LOG_LEVEL    => 'DEBUG ',
25
};
26
27
use Data::Dumper;
6
use Data::Dumper;
28
7
29
our $log = undef;
30
31
sub new {
8
sub new {
32
    my ( $proto, $params ) = @_;
9
    my ( $proto, $params ) = @_;
33
34
    return $log
35
      if $log
36
          and (  not defined $params->{file}
37
              or not defined $log->{FILE_PATH}
38
              or $params->{file} eq $log->{FILE_PATH} );
39
    my $class    = ref($proto) || $proto;
10
    my $class    = ref($proto) || $proto;
40
    my $self     = {};
11
    my $self     = {};
41
    my $LOG_PATH = defined $ENV{KOHA_LOG} ? $ENV{KOHA_LOG} : undef;
12
    my $LOG_PATH = defined $ENV{KOHA_LOG} ? $ENV{KOHA_LOG} : undef;
42
    $self->{FILE_PATH} = defined $params->{file}  ? $params->{file}  : $LOG_PATH;
13
    $self->{FILE_PATH} = defined $params->{file}  ? $params->{file}  : $LOG_PATH;
43
    $self->{LEVEL}     = defined $params->{level} ? $params->{level} : $INFO_LOG_LEVEL;
14
    $self->{LEVEL}     = defined $params->{level} ? $params->{level} : 5;
44
    $self->{LOGGED_MESSAGES} = [];
15
    $self->{LOGGED_MESSAGES} = [];
45
16
46
    if ( not defined $self->{FILE_PATH} ) {
17
    if ( not defined $self->{FILE_PATH} ) {
Lines 54-59 sub new { Link Here
54
sub _write {
25
sub _write {
55
    my ( $self, $msg, $log_level, $dump, $cb ) = @_;
26
    my ( $self, $msg, $log_level, $dump, $cb ) = @_;
56
27
28
    my $LEVEL_STR = {
29
        1 => 'UNUS  ',
30
        2 => 'CRIT  ',
31
        3 => 'ERROR ',
32
        4 => 'WARN  ',
33
        5 => 'NORMAL',
34
        6 => 'INFO  ',
35
        7 => 'DEBUG ',
36
    };
57
    if ( not $self->{LOGGER} ) {
37
    if ( not $self->{LOGGER} ) {
58
        if ( $log_level <= $self->{LEVEL} ) {
38
        if ( $log_level <= $self->{LEVEL} ) {
59
            print STDERR "[" . localtime() . "] " . "$LEVEL_STR->{$log_level}: " . $msg . ( $cb ? " (" . $cb . ")" : "" ) . "\n";
39
            print STDERR "[" . localtime() . "] " . "$LEVEL_STR->{$log_level}: " . $msg . ( $cb ? " (" . $cb . ")" : "" ) . "\n";
Lines 76-120 sub _write { Link Here
76
sub unusable {
56
sub unusable {
77
    my ( $self, $msg, $dump ) = @_;
57
    my ( $self, $msg, $dump ) = @_;
78
    my $cb = $self->_called_by();
58
    my $cb = $self->_called_by();
79
    $self->_write( $msg, $UNUSABLE_LOG_LEVEL, $dump, $cb );
59
    $self->_write( $msg, 1, $dump, $cb );
80
}
60
}
81
61
82
sub critical {
62
sub critical {
83
    my ( $self, $msg, $dump ) = @_;
63
    my ( $self, $msg, $dump ) = @_;
84
    my $cb = $self->_called_by();
64
    my $cb = $self->_called_by();
85
    $self->_write( $msg, $CRITICAL_LOG_LEVEL, $dump, $cb );
65
    $self->_write( $msg, 2, $dump, $cb );
86
}
66
}
87
67
88
sub error {
68
sub error {
89
    my ( $self, $msg, $dump ) = @_;
69
    my ( $self, $msg, $dump ) = @_;
90
    my $cb = $self->_called_by();
70
    my $cb = $self->_called_by();
91
    $self->_write( $msg, $ERROR_LOG_LEVEL, $dump, $cb );
71
    $self->_write( $msg, 3, $dump, $cb );
92
}
72
}
93
73
94
sub warning {
74
sub warning {
95
    my ( $self, $msg, $dump ) = @_;
75
    my ( $self, $msg, $dump ) = @_;
96
    my $cb = $self->_called_by();
76
    my $cb = $self->_called_by();
97
    $self->_write( $msg, $WARNING_LOG_LEVEL, $dump, $cb );
77
    $self->_write( $msg, 4, $dump, $cb );
98
}
78
}
99
79
100
sub log {
80
sub log {
101
    my ( $self, $msg, $dump ) = @_;
81
    my ( $self, $msg, $dump ) = @_;
102
    $self->_write( $msg, $NORMAL_LOG_LEVEL, $dump );
82
    $self->_write( $msg, 5, $dump );
103
}
83
}
104
84
105
sub normal {
85
sub normal {
106
    my ( $self, $msg, $dump ) = @_;
86
    my ( $self, $msg, $dump ) = @_;
107
    $self->_write( $msg, $NORMAL_LOG_LEVEL, $dump );
87
    $self->_write( $msg, 5, $dump );
108
}
88
}
109
89
110
sub info {
90
sub info {
111
    my ( $self, $msg, $dump ) = @_;
91
    my ( $self, $msg, $dump ) = @_;
112
    $self->_write( $msg, $INFO_LOG_LEVEL, $dump );
92
    $self->_write( $msg, 6, $dump );
113
}
93
}
114
94
115
sub debug {
95
sub debug {
116
    my ( $self, $msg, $dump ) = @_;
96
    my ( $self, $msg, $dump ) = @_;
117
    $self->_write( $msg, $DEBUG_LOG_LEVEL, $dump );
97
    $self->_write( $msg, 7, $dump );
118
}
98
}
119
99
120
sub level {
100
sub level {
(-)a/opac/opac-search.pl (-2 / +2 lines)
Lines 51-64 use C4::Tags qw(get_tags); Link Here
51
use C4::Branch; # GetBranches
51
use C4::Branch; # GetBranches
52
use C4::SocialData;
52
use C4::SocialData;
53
use C4::Ratings;
53
use C4::Ratings;
54
use Koha::Utils::Logger qw/$log/;
54
use Koha::Utils::Logger;
55
55
56
use POSIX qw(ceil floor strftime);
56
use POSIX qw(ceil floor strftime);
57
use URI::Escape;
57
use URI::Escape;
58
use Storable qw(thaw freeze);
58
use Storable qw(thaw freeze);
59
use Business::ISBN;
59
use Business::ISBN;
60
60
61
$log = Koha::Utils::Logger->new({level => C4::Context->preference("LogLevel")});
61
my $log = Koha::Utils::Logger->new({level => C4::Context->preference("LogLevel")});
62
62
63
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
63
my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
64
# create a new CGI object
64
# create a new CGI object
(-)a/t/Logger.t (-8 / +2 lines)
Lines 4-22 use utf8; Link Here
4
use Modern::Perl;
4
use Modern::Perl;
5
5
6
use Test::More;
6
use Test::More;
7
require C4::Context;
7
plan tests => 13;
8
import C4::Context;
9
plan tests => 15;
10
8
11
$ENV{KOHA_LOG} = q{/tmp/logger.log};
9
$ENV{KOHA_LOG} = q{/tmp/logger.log};
12
10
13
my $logfile = $ENV{KOHA_LOG};
11
my $logfile = $ENV{KOHA_LOG};
14
12
15
use_ok('Koha::Utils::Logger');
13
use_ok('Koha::Utils::Logger');
16
isnt(C4::Context->preference("LogLevel"), undef, "Check LogLevel syspref");
14
my $log = Koha::Utils::Logger->new({level => 3});
17
use Koha::Utils::Logger qw/$log/;
18
is($log, undef, "Check \$log is undef");
19
$log = Koha::Utils::Logger->new({level => 3});
20
isnt($log, undef, "Check \$log is not undef");
15
isnt($log, undef, "Check \$log is not undef");
21
16
22
17
23
- 

Return to bug 8190