NAME
Log::Log4perl::DataDumper - Wrapper for Log4perl auto Data::Dumper objects
SYNOPSIS
use Log::Log4perl qw(get_logger);
use Log::Log4perl::DataDumper;
my $logger = get_logger();
Log::Log4perl::DataDumper::override($logger);
$logger->debug('Some Object: ', ['an', 'array'],
'Another: ', { a => 'b' });
DESCRIPTION
The Log4perl FAQ has the question "How can I drill down on references before logging them?"
As discussed there, you don't want to say
$logger->debug(Data::Dumper::Dumper($objref))
since the Dumper() will get called regardless of whether debugging is on or not.
This can be handled optimally a couple ways with the stock Log4perl mechanisms:
$logger->debug(sub { Data::Dumper::Dumper($objref) });
or
$logger->debug( {filter => \&Data::Dumper::Dumper,
value => $objref} );
both of which are sort of ugly.
After calling Log::Log4perl::DataDumper::override($logger)
, you can just say:
$logger->debug($objref);
As a special added bonus, you can add an extra flag to the override line:
Log::Log4perl::DataDumper::override($logger, 1)
and it will automatically handle multiline messages in the style of Log::Log4perl::Layout::PatternLayout::Multiline, but it will work with any Layout defined instead of just PatternLayout since they are handled "up front" so to speak.
SEE ALSO
L<Log::Log4perl>
L<Data::Dumper>
AUTHOR
Curt Tilmes, <ctilmes@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2008 by Curt Tilmes
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.