Log::AutoDump - Log with automatic dumping of references and objects.
Logging as usual, but with automatic dumping of references and objects.
use Log::AutoDump; my $log = Log::AutoDump->new; $log->msg( 4, "Logging at level 4 (debug)", $ref, $hashref ); $log->warn( "Logging at warn level (2)", \@somelist, "Did you see that list?!" )
When logging in development, it is common to dump a reference or object.
When working with logging systems that employ the idea of "log-levels", you can quickly end up with expensive code.
$log->warn( "Some object:", Dumper( $obj ), "Did you like that?" );
If the level for the
$log object is set lower than warn, the above log statement will never make it to any log file, or database.
Unfortunately, you have still
Dumped an entire data-structure, just in case.
We take the dumping process out of your hands.
The above statement becomes...
$log->warn( "Some object:", $obj, "Did you like that?" );
Which is easier to read/write for a start, but will also dump the
obj by default.
Using Data::Dumper unless specified.
You can control the
$Data::Dumper::Maxdepth by setting the
dump_depth attribute at construction time, and/or change it later.
my $log = Log::AutoDump->new( dump_depth => 3 ); $log->dump_depth( 1 );
This is useful when dealing with some references or objects that may contain things like DateTime objects, which are themselves huge.
Creates a new logger object.
my $log = Log::AutoDump->new( level => 3, dumps => 1, dump_depth => 2, sort_keys => 1, quote_keys => 0, filename_datestamp => 1, );
Changes the log level for the current instance.
$log->level( 3 );
Controls whether references and objects are dumped or not.
$log->dumps( 1 );
$log->dump_depth( 3 );
$log->sort_keys( 0 );
$log->quote_keys( 0 );
Set the filename.
$log->filename( 'foo.log' );
Set the autoflush on the filehandle.
$log->autoflush( 1 );
This method expects a log level as the first argument, followed by a list of log messages/references/objects.
This is the core method called by the following (preferred) methods, using the below mapping...
TRACE => 5 DEBUG => 4 INFO => 3 WARN => 2 ERROR => 1 FATAL => 0
$log->trace( "Trace some info" );
trace statement is generally used for extremely low level logging, calling methods, getting into methods, etc.
$log->debug( "Debug some info" );
$log->info( "Info about something" );
$log->warn( "Something not quite right here" );
$log->error( "Something went wrong" );
$log->fatal( "Looks like we died" );
simple scripts (the caller stack)
extend to use variations of Data::Dumper
<rob at intelcompute.com>
Please report any bugs or feature requests to
bug-log-autodump at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Log-AutoDump. I will be notified, and then you will automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
Copyright 2012 Rob Brown.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.