Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Applied patch by Peter Rabbitson, which fixes the caller()

level when calling get_logger() on a subclass of Log4perl.
  • Loading branch information...
commit 35d86ae53859424ea3ac357eaf0f15d9e69f4bed 1 parent ddc1e0c
mschilli authored
Showing with 31 additions and 40 deletions.
  1. +4 −0 Changes
  2. +4 −6 lib/Log/Log4perl.pm
  3. +23 −34 lib/Log/Log4perl/Logger.pm
View
4 Changes
@@ -5,6 +5,10 @@
TODO: -config sanity test
-config rollback
+1.19 (2008/09/10)
+ * (ms) Applied patch by Peter Rabbitson, which fixes the caller()
+ level when calling get_logger() on a subclass of Log4perl.
+
1.18 (2008/08/23)
* (ms) Added explanation that categories and loggers are the same
thing (thanks to Rabbit).
View
10 lib/Log/Log4perl.pm
@@ -100,8 +100,6 @@ sub import {
if(exists $tags{':levels'}) {
# Export log levels ($DEBUG, $INFO etc.) from Log4perl::Level
- my $caller_pkg = caller();
-
for my $key (keys %Log::Log4perl::Level::PRIORITY) {
my $name = "$caller_pkg\::$key";
# Need to split this up in two lines, or CVS will
@@ -354,12 +352,12 @@ sub get_logger { # Get an instance (shortcut)
if(@_ == 0) {
# 1
- $category = scalar caller();
+ $category = scalar caller($Log::Log4perl::caller_depth);
} elsif(@_ == 1) {
# 2, 3
if($_[0] eq __PACKAGE__) {
# 2
- $category = scalar caller();
+ $category = scalar caller($Log::Log4perl::caller_depth);
} else {
$category = $_[0];
}
@@ -2591,8 +2589,8 @@ our
Ateeq Altaf, Cory Bennett, Jeremy Bopp, Hutton Davidson, Chris R.
Donnelly, Matisse Enzer, Hugh Esco, James FitzGibbon, Carl Franks,
Dennis Gregorovic, Andy Grundman, Paul Harrington, David Hull,
- Robert Jacobson, Jeff Macdonald, Markus Peter, Brett Rann, Erik
- Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang.
+ Robert Jacobson, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson,
+ Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang.
=head1 COPYRIGHT AND LICENSE
View
57 lib/Log/Log4perl/Logger.pm
@@ -833,30 +833,20 @@ sub init_warn {
# call me from a sub-func to spew the sub-func's caller
#######################################################
sub callerline {
- # the below could all be just:
- # my ($pack, $file, $line) = caller(2);
- # but if we every bury this further, it'll break. So we do this
- # little trick stolen and paraphrased from Carp/Heavy.pm
- my($message) = @_;
+ my $message = join ('', @_);
- my $i = 0;
- my (undef, $localfile, undef) = caller($i++);
- my ($pack, $file, $line);
- do {
- ($pack, $file, $line) = caller($i++);
- } while ($file && $file eq $localfile);
+ my ($pack, $file, $line) = caller($Log::Log4perl::caller_depth + 1);
- my $has_newline;
+ if (not chomp $message) { # no newline
+ $message .= " at $file line $line";
- $has_newline++ if chomp $message;
-
- $message .= " at $file line $line" if !$has_newline;
-
- # Someday, we'll use Threads. Really.
- if (defined &Thread::tid) {
- my $tid = Thread->self->tid;
- $message .= " thread $tid" if $tid and !$has_newline;
+ # Someday, we'll use Threads. Really.
+ if (defined &Thread::tid) {
+ my $tid = Thread->self->tid;
+ $message .= " thread $tid" if $tid;
+ }
}
+
return ($message, "\n");
}
@@ -864,15 +854,14 @@ sub callerline {
sub and_warn {
#######################################################
my $self = shift;
- my $msg = join("", @_[0 .. $#_]);
- CORE::warn(callerline($self->warning_render(@_[0 .. $#_])));
+ CORE::warn(callerline($self->warning_render(@_)));
}
#######################################################
sub and_die {
#######################################################
my $self = shift;
- die(callerline($self->warning_render(@_[0 .. $#_])));
+ die(callerline($self->warning_render(@_)));
}
##################################################
@@ -936,11 +925,11 @@ sub logcluck {
if ($self->is_warn()) {
my $message = Carp::longmess($msg);
- local $Log::Log4perl::caller_depth =
- $Log::Log4perl::caller_depth + 1;
+ $Log::Log4perl::caller_depth++;
foreach (split(/\n/, $message)) {
$self->warn("$_\n");
}
+ $Log::Log4perl::caller_depth--;
Carp::cluck($msg);
}
}
@@ -955,11 +944,11 @@ sub logcarp {
if ($self->is_warn()) {
my $message = Carp::shortmess($msg);
- local $Log::Log4perl::caller_depth =
- $Log::Log4perl::caller_depth + 1;
+ $Log::Log4perl::caller_depth++;
foreach (split(/\n/, $message)) {
$self->warn("$_\n");
}
+ $Log::Log4perl::caller_depth--;
Carp::carp($msg) if $Log::Log4perl::LOGDIE_MESSAGE_ON_STDERR;
}
}
@@ -974,13 +963,13 @@ sub logcroak {
local $Carp::CarpLevel = $Carp::CarpLevel + 1;
my $msg = $self->warning_render(@_);
- my $message = Carp::shortmess($msg);
- local $Log::Log4perl::caller_depth =
- $Log::Log4perl::caller_depth + 1;
if ($self->is_fatal()) {
+ my $message = Carp::shortmess($msg);
+ $Log::Log4perl::caller_depth++;
foreach (split(/\n/, $message)) {
$self->fatal("$_\n");
}
+ $Log::Log4perl::caller_depth--;
}
$Log::Log4perl::LOGDIE_MESSAGE_ON_STDERR ?
@@ -993,16 +982,16 @@ sub logconfess {
##################################################
my $self = shift;
- my $msg = $self->warning_render(@_);
local $Carp::CarpLevel = $Carp::CarpLevel + 1;
+ my $msg = $self->warning_render(@_);
- my $message = Carp::longmess($msg);
- local $Log::Log4perl::caller_depth =
- $Log::Log4perl::caller_depth + 1;
if ($self->is_fatal()) {
+ my $message = Carp::longmess($msg);
+ $Log::Log4perl::caller_depth++;
foreach (split(/\n/, $message)) {
$self->fatal("$_\n");
}
+ $Log::Log4perl::caller_depth--;
}
$Log::Log4perl::LOGDIE_MESSAGE_ON_STDERR ?
Please sign in to comment.
Something went wrong with that request. Please try again.