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