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

In reply to Log::Log4perl suddenly throws up error by chanakya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.