NAME
Log::AutoDump - Log with automatic dumping of references.
VERSION
Version 0.01
SYNOPSIS
Logging, 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, it is common to want to dump a reference/object.
However, 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 be ignored.
But, you have still Dumped
an entire data-structure.
Log::AutoDump
takes the Dumping
process out of your hands.
The above statement now becomes...
$log->warn( "Some object:", $obj, "Did you like that?" );
Which is easier to read/write for a start, but also depending on the $log-\
dumps> flag will either be dumped or not.
The dumps
option is on by default.
We use Data::Dumper by default.
You can also control the $Data::Dumper::Maxdepth
by setting the dump_depth
attribute at construction time, or later.
$log = Log::AutoDump->new( dump_depth => 3 );
$log->dump_depth( 1 );
This becomes useful when dealing with references/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;
Instance Methods
level
Sets the log level for the current instance.
$log->level( 3 );
dumps
Controls whether references/objects are dumped or not.
$log->dumps( 1 );
dump_depth
Set the dump-depth.
$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...
FATAL => 0;
ERROR => 1;
WARN => 2;
INFO => 3;
DEBUG => 4;
TRACE => 5;
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
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.