fix broken Log::Log4perl test
[p5sagit/Log-Contextual.git] / t / log4perl.t
CommitLineData
70a05830 1use strict;
2use warnings;
3
4use Test::More;
5
afe9b141 6if (!eval "use Log::Log4perl;
7 die if $Log::Log4perl::VERSION < 1.29;
8 1") {
9 plan skip_all => 'Log::Log4perl 1.29 not installed'
70a05830 10} else {
11 plan tests => 2;
12}
13
14use FindBin;
15unlink 'myerrs.log' if -e 'myerrs.log';
16Log::Log4perl->init("$FindBin::Bin/log4perl.conf");
17use Log::Contextual qw( :log set_logger );
18set_logger(Log::Log4perl->get_logger);
19
20log_error { 'err 14' };
21
22sub foo {
23 log_error { 'err 17' };
24}
25foo();
26open my $log, '<', 'myerrs.log';
27my @datas = <$log>;
28close $log;
29
afe9b141 30is $datas[0], "file:t/log4perl.t line:20 method:main:: - err 14\n", 'file and line work with Log4perl';
31is $datas[1], "file:t/log4perl.t line:23 method:main::foo - err 17\n", 'file and line work with Log4perl in a sub';
70a05830 32