NAME
Log::AutoDump - Log with automatic dumping of references and objects.
VERSION
Version 0.04
SYNOPSIS
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", $ref, $hashref );
$log->warn( "Logging at warn level (2)", \@somelist, "Did you see that list?!" )
DESCRIPTION
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.
But 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.
METHODS
Class Methods
new
Creates a new logger object.
my $log = Log::AutoDump->new( level => 3, dumps => 1, dump_depth => 2, datestamp_filename => 0 );
By default log filenames will have the current datestamp prefixed, to turn this off, set the flag to false at construction time.
Instance Methods
level
Changes the log level for the current instance.
$log->level( 3 );
dumps
Controls whether references and objects are dumped or not.
$log->dumps( 1 );
dump_depth
Set the $Data::Dumper::Maxdepth
.
$log->dump_depth( 3 );
filename
Set the filename.
$log->filename( 'foo.log' );
msg
$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
trace
$log->trace( "Trace some info" );
A trace
statement is generally used for extremely low level logging, calling methods, getting into methods, etc.
debug
$log->debug( "Debug some info" );
info
$log->info( "Info about something" );
warn
$log->warn( "Something not quite right here" );
error
$log->error( "Something went wrong" );
fatal
$log->fatal( "Looks like we died" );
TODO
simple scripts (the caller stack)
extend to use variations of Data::Dumper
AUTHOR
Rob Brown, <rob at intelcompute.com>
BUGS
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.
SUPPORT
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)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
LICENSE AND COPYRIGHT
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.