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

4

2 回答 2

0

最后,我通过一些实验找到了自己问题的答案。

PatternLayout 使用“调用者”条目作为文件名(和行号等)。但是,方法名称有点复杂。在通常情况下,方法名称也可用于下一级“调用者”(同一级别包含一个ANON)。但是,在某些特殊情况下 eval(例如请求)在“调用者”中进行多级搜索”中进行 eval(例如请求)多级搜索。

此外,request 在导入的文件中没有“有”子程序,因此 %M 返回包含请求的函数,但文件名和行无值引用包含的文件。

作为副作用,您无法使用请求的调用者级别:对于任何级别的“caller_depth”(而不是“<em>caller”),请求的行号都无法访问......

于 2013-07-01T20:49:23.487 回答
0
    %F File where the logging event occurred
    %M Method or function where the logging request was issued
于 2013-06-28T09:54:10.323 回答