I'm trying to extend Log::Log4perl so that I can trap all messages for a process and, at the end, format them all nicely in an email. The example I have below only deals with error messages to more simply demonstrate my issue.

I'm using perl 5.8.2 and Log::Log4perl 1.22

Here is my logger package:

package Mylogger; use warnings; use strict; use base qw(Log::Log4perl); my @error_msgs; sub init { Log::Log4perl::init(@_); return; } sub get_logger { $Log::Log4perl::caller_depth = 1; my $logger = Log::Log4perl::get_logger(@_); bless $logger, __PACKAGE__; return $logger; } sub error { my ($this, $msg) = @_; push(@error_msgs, "ERROR $msg"); $this->SUPER::error($msg); return; } sub get_logged_errors { return \@error_msgs; } 1;
Here is my test program:
use strict; use warnings; use FindBin; use Mylogger; my $conf = q( log4perl.rootLogger=DEBUG, Screen log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.stderr = 0 log4perl.appender.Screen.layout=PatternLayout log4perl.appender.Screen.layout.ConversionPattern=%d{ISO8601} %-5p + %C %m%n ); Mylogger::init(\$conf); my $log = Mylogger::get_logger(); $log->error('error 1'); $log->error('error 2');
Here is a run of my test program showing two errors:
#test.pl Can't locate object method "error" via package "Mylogger" at Mylogger. +pm line 25. Can't locate object method "DESTROY" via package "Mylogger" at /usr/op +t/perl5/lib/site_perl/5.8.2/Log/Log4perl/Logger.pm line 60. END failed--call queue aborted.
The error on line 25 in MyLogger is the call the SUPER::error, which somehow cannot be found. Also there is some issue with the way I'm implementing this which causes Log4perl to not find a DESTROY method. What am I missing here?

In reply to trying to extend Log::Log4perl by mifflin

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.