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

(-)a/Koha/Logger.pm (-3 / +3 lines)
Lines 87-101 sub AUTOLOAD { Link Here
87
        #do not use log4perl; no print to stderr
87
        #do not use log4perl; no print to stderr
88
    }
88
    }
89
    elsif ( !$self->_recheck_logfile ) {
89
    elsif ( !$self->_recheck_logfile ) {
90
        print STDERR "Log file not writable for log4perl\n";
90
        warn "Log file not writable for log4perl";
91
        print STDERR "$method: $line\n" if $line;
91
        warn "$method: $line" if $line;
92
    }
92
    }
93
    elsif ( $self->{logger}->can($method) ) {    #use log4perl
93
    elsif ( $self->{logger}->can($method) ) {    #use log4perl
94
        $self->{logger}->$method($line);
94
        $self->{logger}->$method($line);
95
        return 1;
95
        return 1;
96
    }
96
    }
97
    else {                                       # we should not really get here
97
    else {                                       # we should not really get here
98
        print STDERR "ERROR: Unsupported method $method\n";
98
        warn "ERROR: Unsupported method $method";
99
    }
99
    }
100
    return;
100
    return;
101
}
101
}
(-)a/t/Logger.t (-4 / +32 lines)
Lines 1-3 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
1
use Modern::Perl;
18
use Modern::Perl;
2
19
3
use C4::Context;
20
use C4::Context;
Lines 6-18 use Koha::Logger; Link Here
6
use File::Temp qw/tempfile/;
23
use File::Temp qw/tempfile/;
7
use Test::MockModule;
24
use Test::MockModule;
8
use Test::More tests => 1;
25
use Test::More tests => 1;
26
use Test::Warn;
9
27
10
subtest 'Test01 -- Simple tests for Koha::Logger' => sub {
28
subtest 'Test01 -- Simple tests for Koha::Logger' => sub {
11
    plan tests => 6;
29
    plan tests => 8;
12
    test01();
30
    test01();
13
};
31
};
14
32
15
sub test01 {
33
sub test01 {
34
35
    my $ret;
16
    my $mContext = new Test::MockModule('C4::Context');
36
    my $mContext = new Test::MockModule('C4::Context');
17
    $mContext->mock( 'config', sub { return; } );
37
    $mContext->mock( 'config', sub { return; } );
18
38
Lines 35-43 HERE Link Here
35
    $logger= Koha::Logger->get({ interface => 'intranet' });
55
    $logger= Koha::Logger->get({ interface => 'intranet' });
36
    is( exists $logger->{logger}, 1, 'Log4perl config found');
56
    is( exists $logger->{logger}, 1, 'Log4perl config found');
37
    is( $logger->warn('Message 2'), 1, 'Message 2 returned a value' );
57
    is( $logger->warn('Message 2'), 1, 'Message 2 returned a value' );
38
    is( $logger->catastrophe, undef, 'catastrophe undefined');
58
    warning_is { $ret = $logger->catastrophe }
59
               "ERROR: Unsupported method catastrophe",
60
               "Undefined method raises warning";
61
    is( $ret, undef, "'catastrophe' method undefined");
39
    system("chmod 400 $log");
62
    system("chmod 400 $log");
40
    is( $logger->warn('Message 3'), undef, 'Message 3 returned undef' );
63
    warnings_are { $ret = $logger->warn('Message 3') }
64
                 [ "Log file not writable for log4perl",
65
                   "warn: Message 3" ],
66
                 "Warnings raised if log file is not writeable";
67
    is( $ret, undef, 'Message 3 returned undef' );
41
}
68
}
42
69
43
sub mytempfile {
70
sub mytempfile {
Lines 46-48 sub mytempfile { Link Here
46
    close $fh;
73
    close $fh;
47
    return $fn;
74
    return $fn;
48
}
75
}
49
- 
76
77
1;

Return to bug 14167