Commit | Line | Data |
70a05830 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | |
6ae293d7 |
6 | if ( |
7 | eval <<'EOE' |
f929c548 |
8 | require Log::Log4perl; |
9 | die if $Log::Log4perl::VERSION < 1.29; |
10 | 1 |
11 | EOE |
6ae293d7 |
12 | ) { |
70a05830 |
13 | plan tests => 2; |
f929c548 |
14 | } else { |
15 | plan skip_all => 'Log::Log4perl 1.29 not installed' |
70a05830 |
16 | } |
17 | |
18 | use FindBin; |
19 | unlink 'myerrs.log' if -e 'myerrs.log'; |
20 | Log::Log4perl->init("$FindBin::Bin/log4perl.conf"); |
21 | use Log::Contextual qw( :log set_logger ); |
22 | set_logger(Log::Log4perl->get_logger); |
23 | |
f929c548 |
24 | my @elines; |
25 | |
26 | push @elines, __LINE__ and log_error { 'err FIRST' }; |
70a05830 |
27 | |
28 | sub foo { |
f929c548 |
29 | push @elines, __LINE__ and log_error { 'err SECOND' }; |
70a05830 |
30 | } |
31 | foo(); |
32 | open my $log, '<', 'myerrs.log'; |
33 | my @datas = <$log>; |
34 | close $log; |
35 | |
6ae293d7 |
36 | is $datas[0], "file:t/log4perl.t line:$elines[0] method:main:: - err FIRST\n", |
37 | 'file and line work with Log4perl'; |
38 | is $datas[1], |
39 | "file:t/log4perl.t line:$elines[1] method:main::foo - err SECOND\n", |
40 | 'file and line work with Log4perl in a sub'; |
70a05830 |
41 | |
308f4c2a |
42 | unlink 'myerrs.log'; |