I've been using
Log::Log4perl in my project. Lately I've been experiencing logging issues/errors on some of the scripts.
Below is the error I see whenever the script is executed. Sometimes the below error is thrown in a working script too
Undefined subroutine &main::get_log called at (eval 8) line 1.
Compilation failed in require at ./read_dirs.pl line 20.
BEGIN failed--compilation aborted at ./read_dirs.pl line 20.
Below is my setup:
1) Every ".pl" has a corresponding module. The logging level for each module is defined in log4perl.conf
2) All ".pl" files and modules log the ERROR/INFO/DEBUG/FATAL messages into a logfile which is unique for each day
Below is my config, the module and the perl script:
##log4perl.conf
[log4perl]
log4perl.logger= DEBUG,Logfile, Screen
log4perl.appender.Logfile = Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename = sub { return get_log(); }
log4perl.appender.Logfile.mode = append
log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayou
+t
log4perl.appender.Logfile.layout.ConversionPattern = %d %p> %m%n
log4perl.appender.DEBUG= Log::Log4perl::Appender::File
log4perl.appender.DEBUG.filename = sub { return get_log(); }
log4perl.appender.DEBUG.mode = append
log4perl.appender.DEBUG.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.DEBUG.layout.ConversionPattern = %d %p> %m%n
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 = %d %p> %m%n
[Modules level setup]
log4perl.logger.main = INFO
log4perl.logger.MyCompany::Util::PARSE_DIR = DEBUG
log4perl.logger.MyCompany::Util::CREATE_DIR = INFO
##PARSE_DIR.pm
package MyCompany::Util::PARSE_DIR
use strict;
use warnings;
use Log::Log4perl qw(:easy);
Log::Log4perl::init( $ENV{CONF_DIR} . '/' ."log4perl.conf" );
my $logger = Log::Log4perl::get_logger("MyCompany::Util::PARSE_DIR");
$logger->info("Started processing");
1;
##read_dirs.pl
#!/usr/bin/perl
use strict;
use warnings;
use Log::Log4perl qw(:easy);
use MyCompany::Util::PARSE_DIR;
##Initializations
Log::Log4perl::init( "$ENV{CONF_DIR}" . "/log4perl.conf" );
my $logger = Log::Log4perl::get_logger();
my $dir = "test";
my $data = MyCompany::Util::PARSE_DIR::get_data({dir=> $dir});
$logger->warn("could not get data") if (!$data);
sub get_log{
use File::Basename;
use POSIX qw(strftime);
my $now_string = strftime("%Y-%m-%d", localtime);
my $log = sprintf "%s.$now_string.log", basename( $0, '.pl' );
return "$ENV{LOG_DIR}" . '/'. $log;
}
Please let me know whether its a problem with the script and how to fix the problem.
Thanks in advance for your time