I want to get appender file name using logger object.
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);
I went over doc and it says that I can access appenders using appender_by_name()
class method.
I tried to access it using the command $logger->appender_by_name()
, but it is returning me following error:
Can't locate object method "appender_by_name" via package "Log::Log4perl::Logger"
Perl Version: 5.22
Log::Log4perl Version: 1.48
Following is the dump of my logger object:
$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' );