NAME
Log::AutoDump - Log with automatic dumping of references and objects.
VERSION
Version 0.23
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 (debug)", $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.
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.
METHODS
Class Methods
new
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,
);
Instance Methods
level
Changes the log level for the current instance.
$log->level( 3 );
history_length
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 );
history
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;
dumps
Controls whether references and objects are dumped or not.
$log->dumps( 1 );
dump_depth
Sets $Data::Dumper::Maxdepth
.
$log->dump_depth( 3 );
sort_keys
Sets $Data::Dumper::Sortkeys
.
$log->sort_keys( 0 );
quote_keys
Sets $Data::Dumper::Quotekeys
.
$log->quote_keys( 0 );
deep_copy
Sets $Data::Dumper::Deepcopy
.
$log->deep_copy( 0 );
purity
Sets $Data::Dumper::Purity
.
$log->purity( 0 );
filename
Set the filename.
$log->filename( 'foo.log' );
autoflush
Set the autoflush on the filehandle.
$log->autoflush( 1 );
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.