sub log_trace (&@) {
my $log = _get_logger( caller );
my $code = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->trace($code->(@_))
if $log->is_trace;
@_
sub log_debug (&@) {
my $log = _get_logger( caller );
my $code = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->debug($code->(@_))
if $log->is_debug;
@_
sub log_info (&@) {
my $log = _get_logger( caller );
my $code = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->info($code->(@_))
if $log->is_info;
@_
sub log_warn (&@) {
my $log = _get_logger( caller );
my $code = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->warn($code->(@_))
if $log->is_warn;
@_
sub log_error (&@) {
my $log = _get_logger( caller );
my $code = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->error($code->(@_))
if $log->is_error;
@_
sub log_fatal (&@) {
my $log = _get_logger( caller );
my $code = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->fatal($code->(@_))
if $log->is_fatal;
@_
my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->trace($code->($value))
if $log->is_trace;
$value
my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->debug($code->($value))
if $log->is_debug;
$value
my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->info($code->($value))
if $log->is_info;
$value
my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->warn($code->($value))
if $log->is_warn;
$value
my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->error($code->($value))
if $log->is_error;
$value
my $log = _get_logger( caller );
my $code = shift;
my $value = shift;
+ local $Log::Log4perl::caller_depth = ($Log::Log4perl::caller_depth || 0 ) + 1;
$log->fatal($code->($value))
if $log->is_fatal;
$value
--- /dev/null
+############################################################
+# A simple root logger with a Log::Log4perl::Appender::File
+# file appender in Perl.
+############################################################
+log4perl.rootLogger=ERROR, LOGFILE
+
+log4perl.appender.LOGFILE=Log::Log4perl::Appender::File
+log4perl.appender.LOGFILE.filename=myerrs.log
+log4perl.appender.LOGFILE.mode=append
+
+log4perl.appender.LOGFILE.layout=PatternLayout
+log4perl.appender.LOGFILE.layout.ConversionPattern=file:%F line:%L method:%M - %m%n
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+
+if (!eval "use Log::Log4perl; 1") {
+ plan skip_all => 'Log::Log4perl not installed'
+} else {
+ plan tests => 2;
+}
+
+use FindBin;
+unlink 'myerrs.log' if -e 'myerrs.log';
+Log::Log4perl->init("$FindBin::Bin/log4perl.conf");
+use Log::Contextual qw( :log set_logger );
+set_logger(Log::Log4perl->get_logger);
+
+log_error { 'err 14' };
+
+sub foo {
+ log_error { 'err 17' };
+}
+foo();
+open my $log, '<', 'myerrs.log';
+my @datas = <$log>;
+close $log;
+
+is $datas[0], "file:t/log4perl.t line:18 method:main:: - err 14\n", 'file and line work with Log4perl';
+is $datas[1], "file:t/log4perl.t line:21 method:main::foo - err 17\n", 'file and line work with Log4perl in a sub';
+