Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-25 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found