3 # This file is part of Koha.
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.
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.
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>.
24 use File
::Temp qw
/tempfile/;
25 use Test
::More tests
=> 1;
28 subtest
'Test01 -- Simple tests for Koha::Logger' => sub {
32 t
::lib
::Mocks
::mock_config
('log4perl_conf', undef);
34 eval { Koha
::Logger
->get };
35 ok
( $@
, 'Logger did not init correctly without config');
37 my $log = mytempfile
();
38 my $config_file = mytempfile
( <<"HERE"
39 log4perl.logger.intranet = WARN, INTRANET
40 log4perl.appender.INTRANET=Log::Log4perl::Appender::File
41 log4perl.appender.INTRANET.filename=$log
42 log4perl.appender.INTRANET.mode=append
43 log4perl.appender.INTRANET.layout=PatternLayout
44 log4perl.appender.INTRANET.layout.ConversionPattern=[%d] [%p] %m %l %n
48 t
::lib
::Mocks
::mock_config
('log4perl_conf', $config_file);
50 system("chmod 400 $log");
51 eval { Koha
::Logger
->get };
52 ok
( $@
, 'Logger did not init correctly without permission');
54 system("chmod 700 $log");
55 my $logger= Koha
::Logger
->get({ interface
=> 'intranet' });
56 is
( exists $logger->{logger
}, 1, 'Log4perl config found');
57 is
( $logger->warn('Message 1'), 1, '->warn returned a value' );
58 warning_is
{ $ret = $logger->catastrophe }
59 "ERROR: Unsupported method catastrophe",
60 "Undefined method raises warning";
61 is
( $ret, undef, "'catastrophe' method undefined");
66 my ( $fh, $fn ) = tempfile
( SUFFIX
=> '.logger.test', UNLINK
=> 1 );