Log::AutoDump - Log with automatic dumping of references and objects.
Version 0.23
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.
For example...
$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.
$log
Unfortunately, you have still Dumped an entire data-structure, just in case.
Dumped
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.
obj
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.
$Data::Dumper::Maxdepth
dump_depth
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, deep_copy => 1, filename_datestamp => 1, );
Changes the log level for the current instance.
$log->level( 3 );
Controls how many historical log events to remember.
This is the number of events, not number of statments or dumps.
If a debug statement includes 3 messages/objects, all 3 are stored in one unit of length.
$log->history_length( 10 );
The list of historical statements/objects.
Each point in the history is an arrayref of statements/objects.
This is only a getter, the history is accumulated internally.
$log->history;
Controls whether references and objects are dumped or not.
$log->dumps( 1 );
Sets $Data::Dumper::Maxdepth.
$log->dump_depth( 3 );
Sets $Data::Dumper::Sortkeys.
$Data::Dumper::Sortkeys
$log->sort_keys( 0 );
Sets $Data::Dumper::Quotekeys.
$Data::Dumper::Quotekeys
$log->quote_keys( 0 );
Sets $Data::Dumper::Deepcopy.
$Data::Dumper::Deepcopy
$log->deep_copy( 0 );
Sets $Data::Dumper::Purity.
$Data::Dumper::Purity
$log->purity( 0 );
Set the filename.
$log->filename( 'foo.log' );
Set the autoflush on the filehandle.
$log->autoflush( 1 );
$log->msg(2, "Hello");
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" );
A trace statement is generally used for extremely low level logging, calling methods, getting into methods, etc.
trace
$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 Brown, <rob at intelcompute.com>
<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.
bug-log-autodump at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Log::AutoDump
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Log-AutoDump
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Log-AutoDump
CPAN Ratings
http://cpanratings.perl.org/d/Log-AutoDump
Search CPAN
http://search.cpan.org/dist/Log-AutoDump/
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.
To install Log::AutoDump, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::AutoDump
CPAN shell
perl -MCPAN -e shell install Log::AutoDump
For more information on module installation, please visit the detailed CPAN module installation guide.