Dear Monks,

I want to make a generic wrapper class for Log::Log4perl to be used from both Perl modules and Mason components. It works fine when called from Perl modules, but when called from Mason, the logfile reports HTML/Mason/Component.pm as source of the event instead of my source (see below). It seems like increasing the caller_depth jumps the call stack twice instead of just once.
# Module id = Log::Log4perl INST_VERSION 0.37 # Module id = HTML::Mason INST_VERSION 1.23 # This is perl, v5.6.1 built for i386-linux # Server version: Apache/1.3.23 (Unix) (Red-Hat/Linux) package MyLogger; use Log::Log4perl; Log::Log4perl->init("/opt/app/log4perl.conf"); my ($log, $module_name); sub new { my MyLogger $self = shift; unless (ref $self) { $self = fields::new ($self); } $module_name = shift; $log = Log::Log4perl->get_logger($module_name); # compensate for this wrapper class by adding 1 $Log::Log4perl::caller_depth++; return $self; } sub debug{ my ($self, $logmsg) = @_; $log->debug($logmsg) if ($log->is_debug()); }
Log entry sample
2004/01/15 10:48:27 DEBUG> /usr/lib/perl5/site_perl/5.6.1/HTML/Mason/C +omponent.pm:134 [7674] stop
Expected log entry:
2004/01/15 10:48:27 DEBUG> /opt/app/root_dir/login_:13 [7674] stop
Any clues how to make Log4perl report my real source in the log when called from a Mason component?

Andreas
--

In reply to Log::Log4perl wrapper + Mason - wrong source file in log by andreas1234567

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.