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