I've been using log4perl to help keep debugging logs for a web application. Recently, I decided that it would be helpful to include the session ID in every log entry. I thought it would be as simple as declaring a cspec like this: log4perl.PatternLayout.cspec.s = sub {return $session->id}
However, when I run the application, I recieve the following error: Can't evaluate 'sub {return $session->id}' (Global symbol "$session" requires explicit package name at (eval 37) line 1.)at /usr/lib/perl5/site_perl/5.8.0/Log/Log4perl/Config.pm line 708. Initially, I though this was because I was initalizing the log before I had initalized the session. However, after reviewing my code, this is not the case.
Is there some way to make log4perl aware of the value of the session variable? I've included the relevant code below, but I'm not sure what I could do differently.
# Check to see if we have a session. If so, load it's information.
# If not, we need to create one and then cookie the user.
my $session = new CGI::Session("driver:DB_File", $cgi, {Directory=>'/u
+sr/local/apache/htdocs/addressbook'});
# Init the logger
Log::Log4perl->init("/usr/local/apache/htdocs/addressbook/log4perl.con
+f");