On Mon, 8 Nov 2010, Kidwell,jr, Jack wrote:
under any circumstances. Trivial tests show that a disk full condition
causes logging to die.
We want to use Log4perl because of it's features, so what is the
best way to prevent Log4perl from dying.
There's a couple of ways Log4perl can die(), so you need to wrap
eval { };
statements around these sections. One way is if -init() fails, that one
you can easily enclose in an eval {}. When it comes to logging to
a file, this is trickier, because the Log::Log4perl::Appender::File
appender checks if writing to the file succeeds and dies if this fails.
What you can do in this case is define a class that inherits from it and
wraps an eval {} around the log method:
#!/usr/bin/perl -w
use strict;
package NeverDieFileAppender;
use base qw( Log::Log4perl::Appender::File );
sub log {
my($self, @args) = @_;
local $Log::Log4perl::caller_depth =
$Log::Log4perl::caller_depth + 1;
eval { $self-SUPER::log(@args) };
}
package main;
use Log::Log4perl qw(:easy);
Log::Log4perl-init( \q{
log4perl.logger = DEBUG, App
log4perl.appender.App = NeverDieFileAppender
log4perl.appender.App.filename = out.dat
log4perl.appender.App.layout = PatternLayout
log4perl.appender.App.layout.ConversionPattern = %F-%L: %m%n
});
DEBUG waah;
-- Mike
Mike Schilli
m...@perlmeister.com
--
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book Blueprint to a
Billion shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
___
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel