Just added a patch that fixes the subroutine name that comes with %M as
part of the PatternLayout. If a logger is called within an eval {}
block, caller(x) will report "(eval)" as subroutine name, but now we get
the next *real* subroutine:
diff -a -u -r1.43 -r1.44
--- PatternLayout.pm 26 Jan 2004 04:19:13 -0000 1.43
+++ PatternLayout.pm 3 Feb 2004 06:25:52 -0000 1.44
@@ -202,9 +202,18 @@
if($self->{info_needed}->{M} or
$self->{info_needed}->{l} or
0) {
- # For the name of the subroutine the logger was triggered,
- # we need to go one more level up
- $subroutine = (caller($caller_level+1))[3];
+ # To obtain the name of the subroutine which triggered the
+ # logger, we need to go one additional level up.
+ my $levels_up = 1;
+ {
+ $subroutine = (caller($caller_level+$levels_up))[3];
+ # If we're inside an eval, go up one level further.
+ if(defined $subroutine and
+ $subroutine eq "(eval)") {
+ $levels_up++;
+ redo;
+ }
+ }
$subroutine = "main::" unless $subroutine;
$info{M} = $subroutine;
$info{l} = "$subroutine $filename ($line)";
--
-- Mike
Mike Schilli
m...@pe...
|