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