我想使用记录器对象获取附加器文件名。
my $log_conf = {
'log4perl.rootLogger' => "DEBUG, LOG1, SCREEN",
'log4perl.appender.SCREEN' => "Log::Log4perl::Appender::Screen",
'log4perl.appender.SCREEN.stderr' => "0",
'log4perl.appender.SCREEN.layout' => "Log::Log4perl::Layout::PatternLayout",
'log4perl.appender.SCREEN.layout.ConversionPattern' =>
"autom:%d{yyyy_MMM_d H:m:s}_" . get_ip_address() . "_%C::: %m %n",
'log4perl.appender.LOG1' => "Log::Log4perl::Appender::File",
'log4perl.appender.LOG1.filename' => file_path($file_name, $path),
#'log4perl.appender.LOG1.mode' => "append",
'log4perl.appender.LOG1.layout' => "Log::Log4perl::Layout::PatternLayout",
'log4perl.appender.LOG1.layout.ConversionPattern' =>
"autom:%d{yyyy_MMM_d H:m:s}_%C::: %m %n"
};
Log::Log4perl->init($log_conf);
my $logger = Log::Log4perl->get_logger($file_name);
我经过doc,它说我可以使用appender_by_name()
类方法访问附加程序。
我尝试使用命令$logger->appender_by_name()
访问它,但它返回以下错误:
无法通过包“ Log :: Log4perl :: Logger”找到对象方法“ appender_by_name”
Perl Version: 5.22
Log::Log4perl Version: 1.48
以下是我的记录器对象的转储:
$VAR1 = bless( {
'TRACE' => sub { "DUMMY" },
'DEBUG' => sub { "DUMMY" },
'FATAL' => $VAR1->{'DEBUG'},
'additivity' => 1,
'level' => undef,
'layout' => undef,
'appender_names' => [],
'OFF' => $VAR1->{'DEBUG'},
'is_WARN' => sub { "DUMMY" },
'is_TRACE' => sub { "DUMMY" },
'is_OFF' => sub { "DUMMY" },
'is_DEBUG' => sub { "DUMMY" },
'ERROR' => $VAR1->{'DEBUG'},
'is_INFO' => sub { "DUMMY" },
'is_ERROR' => sub { "DUMMY" },
'is_ALL' => sub { "DUMMY" },
'WARN' => $VAR1->{'DEBUG'},
'INFO' => $VAR1->{'DEBUG'},
'num_appenders' => 0,
'is_FATAL' => sub { "DUMMY" },
'category' => 'autom_controller.log',
'ALL' => $VAR1->{'TRACE'}
}, 'Log::Log4perl::Logger' );
答案 0 :(得分:2)
appender_by_name()
是Log::Log4perl
类中的方法。因此,您需要将其用作:
Log::Log4perl->appender_by_name('LOG1')