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");

In reply to Custom cspec's in Net::Log4perl by jpfarmer

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.