0

The original question has been reformulated, to be clear for later use

I find the following issue to be weird. In some cases %M and %F refers to different files. For example int the following case:

Foo.pm contains

use warnings;
sub x { 2; 1; }
1;

test.pl contains

#!/usr/bin/perl
use Log::Log4perl qw/:easy/;
Log::Log4perl->easy_init({ file => 'STDOUT', layout => '[%p{1}] %m{chomp} [%l]%n' });
$::log = Log::Log4perl->get_logger;
local $SIG{__WARN__} = sub {
    local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
    $::log->warn(shift);
};
require "Foo.pm";

Result is:

[W] Useless use of a constant in void context at Foo.pm line 2. [main:: Foo.pm (2)]

So file is "Foo.pm", but the function is "main::".

I found that the weird behavior is in connection with errors/warnings happening in compile time of "require".

Why do %M and %F differ?

Thanks, FERcsI

FERcsI
  • 388
  • 1
  • 10

2 Answers2

0
    %F File where the logging event occurred
    %M Method or function where the logging request was issued
Pavunkumar
  • 5,147
  • 14
  • 43
  • 69
  • Thanks. I've read the POD, just this does not explain the difference between a "warn" and an "error"... – FERcsI Jun 28 '13 at 12:59
0

Finally, I found the answer to my own question through some experiments.

PatternLayout uses "caller" entries for file name (and line no, etc.). However, method names are a bit more complicated. In a usual case method name is also available in the next level of "caller" (the same level contains an ANON). However, in some special cases of eval (e.g. request) multiple level search in "caller" has to be done.

In addition, request does not “have” a subroutine in the imported file, so %M returns the function including the request, but the file name and line no values refer to the included file.

As a side effect, you are not able to use request's caller level: request's line number is unreachable for any level of "caller_depth" (as opposed to “caller”)...

FERcsI
  • 388
  • 1
  • 10