Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Log::Log4perl suddenly throws up error

by chanakya (Friar)
on Aug 07, 2009 at 17:44 UTC ( #786854=perlquestion: print w/replies, xml ) Need Help??

chanakya has asked for the wisdom of the Perl Monks concerning the following question:

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 ./ line 20. BEGIN failed--compilation aborted at ./ 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 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; #!/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

Replies are listed 'Best First'.
Re: Log::Log4perl suddenly throws up error
by zwon (Abbot) on Aug 07, 2009 at 20:56 UTC

    You should define get_log before you are using PARSE_DIR module.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://786854]
Approved by sweetblood
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2022-12-05 21:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found