in reply to Re^2: log4perl collecting (buffering) messages
in thread log4perl collecting (buffering) messages

Hi,

this is now more a MooseX::Log::Log4perl related question. When you look at the perldoc of that package IMHO anything is said. You have to initialize the Log::Log4perl singleton before logging the first time. Example is given in the perldoc.

Init like

my $log4perl_conf = q( log4perl.logger=DEBUG, STRINGCOLLECTOR log4perl.appender.STRINGCOLLECTOR = Log::Log4perl::Appender::String log4perl.appender.STRINGCOLLECTOR.layout = Log::Log4perl::Layout::Patt +ernLayout log4perl.appender.STRINGCOLLECTOR.layout.ConversionPattern = %p:%d{ISO +8601}:myscript: %m%n ); Log::Log4perl->init( \$log4perl_conf );
before first usage.

UPDATE: As the doc says: You can get the logger instance with $self->logger. So later you should get the collected output with

my $appender = $self->logger->appender_by_name('STRINGCOLLECTOR'); my $string = ''; if($appender) { $string = $appender->string(); }

McA

Replies are listed 'Best First'.
Re^4: log4perl collecting (buffering) messages
by coke4all (Novice) on Mar 14, 2013 at 11:44 UTC

    THANKS!!!!!!! you SAID IT ALL. I thinks next time i´ve to read the documentation for the SUPER-Class too ... puhhh ;-)

    In addition i´ve found this:

    "There's no need to pass around logger references between your system's functions. This effectively avoids cluttering up your beautifully crafted functions/methods with parameters unrelated to your implementation. get_logger() can be called by every function/method directly with little overhead in order to obtain a logger. get_logger makes sure that no new object is created unnecessarily. In most cases, it will just cheaply return a reference to an already existing object (singleton mechanism)."

    from: http://www.perl.com/pub/2002/09/11/log4perl.html