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