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

I am trying to use Log4Perl in an application using CGI::Application and running under #!/usr/bin/speedy. I always get this error Internal Error: Root Logger not initialized. Here is my code snippet. I have a Wrapper Module for Logger Logger.pm
use Log::Log4perl; sub set_session_id { my ($class) = shift; my ($session_id) = shift; unless(Log::Log4perl->initialized()) { Log::Log4perl->init_once('/opt/httpd/logger.conf'); $Log::Log4perl::caller_depth = 1; my $user_id = $ENV{USER} || $ENV{LOGNAME} || $ENV{USERNAME} || $EN +V{REMOTE_ USER} || $<; Log::Log4perl->get_logger("esc"); Log::Log4perl::MDC->put("user_id", $user_id); Log::Log4perl::MDC->put("session_id", $session_id); } return Log::Log4perl->get_logger("esc"); } and my logger.conf is log4perl.logger.esc=DEBUG, DBAppndr #log4perl.rootLogger=DEBUG, DBAppndr log4perl.appender.DBAppndr=Log::Log4perl::Appender::DBI log4perl.appender.DBAppndr.datasource=dbi:Oracle:data log4perl.appender.DBAppndr.username=user log4perl.appender.DBAppndr.password=passwd log4perl.appender.DBAppndr.sql=insert into ESC_APP_LOG (LOG_LEVEL, LOG +GER_NAME, MODULE, APP_ID, CLASS, METHOD, LINE_NO, HEADING, USER_ID, M +SG, LOGGER_ID) values (?,?,?,?,?,?,?,?,?,?,?) etc and in my cgiapp_init sub routine I call logger as below my $logger = Logger->set_session_id($self->param('session')); $self->param('logger'=> $logger);
when I start my application, I get this error "Error executing class callback in init stage: Internal error: Root Logger not initialized." I am not sure what I am doing wrong. any help solve my problem is appreciated. Thanks in advance for your help. Thanks Prakash

Replies are listed 'Best First'.
Re: help with Log::Log4perl under CGI::application and speedyCGI
by saintmike (Vicar) on Mar 29, 2006 at 20:34 UTC
    Hmm, this is an internal error in Log4perl, it happens when get_logger() gets called although the system hasn't been completely initialized.

    Could this be a race condition between different threads?

      Hi, Sorry for replying late. I guess it was a problem with the Log4perl module already installed on my system. I reinstalled the Module and everything started working fine. Thanks for taking time to reply.