Log::Log4perl::DataDumper - Wrapper for Log4perl auto Data::Dumper objects


Log-Log4perl-DataDumper documentation  | view source Contained in the Log-Log4perl-DataDumper distribution.

Index


NAME

Top

Log::Log4perl::DataDumper - Wrapper for Log4perl auto Data::Dumper objects

SYNOPSIS

Top

 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

Top

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

Top

 L<Log::Log4perl>
 L<Data::Dumper>

AUTHOR

Top

Curt Tilmes, <ctilmes@cpan.org>

COPYRIGHT AND LICENSE

Top


Log-Log4perl-DataDumper documentation  | view source Contained in the Log-Log4perl-DataDumper distribution.