NAME
Debug::Easy - A Handy Debugging Module With Colorized Output and Formatting
SYNOPSIS
use Debug::Easy;
my $debug = Debug::Easy->new( 'LogLevel' => 'DEBUG', 'Color' => 1 );
# $debug_level is the maximum level to report, and ignore the rest.
# It must be the second parameter passed to the object, when outputing
# a specific message. This identifies to the module what type of
# message it is.
#
# The following is a list, in order of level, of the parameter to
# pass to the debug method:
#
# ERR = Error
# WARN = Warning
# NOTICE = Notice
# INFO = Information
# VERBOSE = Special version of INFO that does not output any
# Logging headings and goes to STDOUT instead of STDERR.
# Very useful for verbose modes in your scripts.
# DEBUG = Level 1 Debugging messages
# DEBUGMAX = Level 2 Debugging messages (typically more terse)
#
# The third parameter is either a string or a reference to an array
# of strings to output as multiple lines. If one of the array
# elements is a reference, then it is passed to the available
# Data Dumping library.
#
# Each string can contain newlines, which will also be split into
# a separate line and formatted accordingly.
my $debug_level = 'NOTICE';
$debug->debug($debug_level,"Message");
$debug->debug('ERR', ['Error message']);
$debug->debug('WARN', ['Warning message']);
$debug->debug('NOTICE', ['Notice message']);
$debug->debug('INFO', ['Information and VERBOSE mode message']);
$debug->debug('DEBUG', ['Level 1 Debug message']);
$debug->debug('DEBUGMAX', ['Level 2 Debug message']);
my @messages = (
'First Message',
'Second Message',
"Third Message First Line\nThird Message Second Line",
\%hash_reference
);
$debug->debug($debug_level,\@messages);
DESCRIPTION
This module makes it easy to add debugging features to your code, Without having to re-invent the wheel. It uses STDERR and ANSI color Formatted text output, as well as indented and multiline text formatting, to make things easy to read. NOTE: It is generally defaulted to output in a format for viewing on wide terminals!
Benchmarking is automatic, to make it easy to spot bottlenecks in code. It automatically stamps from where it was called, and makes debug coding so much easier, without having to include the location of the debugging location in your debug message. This is all taken care of for you.
It also allows multiple output levels from errors only, to warnings, to notices, to verbose information, to full on debug output. All of this fully controllable by the coder.
It is essentially a smart wrapper on top of Log::Fast to enhance it.
EXPORTABLE VARIABLES
@Levels
A simple list of all the acceptable debug levels to pass to the {debug} method,
and the {new} method.
$Modules
A hash reference indicating which of three data dumping modules it has
detected and loaded. The keys are the names of the modules, and the
value is boolean, either 1 or 0:
Data::Printer Data::Dumper::Simple Data::Dumper
METHODS
new
The parameter names are case insensitive as of Version 0.04.
- LogLevel [level]
-
This adjusts the global log level of the Debug object. It requires a string.
- ERR (default)
-
This level shows only error messages and all other messages are not shown.
- WARN
-
This level shows error and warning messages. All other messages are not shown.
- NOTICE
-
This level shows error, warning, and notice messages. All other messages are not shown.
- INFO
-
This level shows error, warning, notice, and information messages. Only debug level messages are not shown.
- VERBOSE
-
This level can be used as a way to do "Verbose" output for your scripts. It ouputs INFO level messages without logging headers and on STDOUT instead of STDERR.
NOTE: A question was asked why this uses STDOUT. The answer is simple, I have never run across a script that sent "verbose" output on STDERR. If you don't like this behavior, then just use the 'INFO' log level instead of 'VERBOSE'.
- DEBUG
-
This level shows error, warning, notice, information, and level 1 debugging messages. Level 2 Debug messages are not shown.
- DEBUGMAX
-
This level shows all messages up to level 2 debugging messages.
NOTE: It has been asked "Why have two debugging levels?" Well, I have had many times where I would like to see what a script is doing without it showing what I consider garbage overhead it may generate. This is simply because the part of the code you are debugging you may not need such a high level of detail. I use 'DEBUGMAX' to show me absolutely everything. Such as Data::Dumper output.
- Color [boolean] (Not case sensitive)
-
- 0, Off, or False (Off)
-
This turns off colored output. Everything is plain text only.
- 1, On, or True (On - Default)
-
This turns on colored output. This makes it easier to spot all of the different types of messages throughout a sea of debug output. You can read the output with Less, and see color, by using it's switch "-r".
- Prefix [pattern]
-
A string that is parsed into the output prefix.
DEFAULT: %D %T %B %L %P
%D = Date (Uses format of "DateStamp" below %T = Time (Uses format of "TimeStamp" below %B = Benchmark %L = Log Level %P = Module and subroutine of call %d = Just Date (typically used internally only, use %D) %t = Just time (typically used internally only, use %T)
- TimeStamp [pattern]
-
(See Log::Fast for specifics on these)
Make this an empty string to turn it off, otherwise:
- DateStamp [pattern]
-
(See Log::Fast for specifics on these)
Make this an empty string to turn it off, otherwise:
- Type
-
Output type. Possible values are: 'fh' (output to any already open filehandle) and 'unix' (output to syslog using UNIX socket).
- fh
-
When set to 'fh', you have to also set {FileHandle} to any open filehandle (like "\*STDERR", which is the default).
- unix
-
When set to 'unix', you have to also set {FileHandle} to a path pointing to an existing unix socket (typically it's '/dev/log').
- FileHandle
-
File handle to write log messages if {Type} set to 'fh' (which is the default). Syslog's UNIX socket path to write log messages if {Type} set to 'unix'.
- ANSILevel
-
Contains a hash reference describing the various colored debug level labels The default definition (using Term::ANSIColor) is as follows:
'ANSILevel' => { 'ERR' => colored(['white on_red'], '[ ERROR ]'), 'WARN' => colored(['black on_yellow'], '[WARNING]'), 'NOTICE' => colored(['black on_magenta'], '[NOTICE ]'), 'INFO' => colored(['white on_black'], '[ INFO ]'), 'DEBUG' => colored(['bold green on_black'],'[ DEBUG ]'), 'DEBUGMAX' => colored(['bold green on_black'],'[-DEBUG-]'), }
debug
The parameters must be passed in the order given
- LEVEL
-
The log level with which this message is to be triggered
- MESSAGE(S)
-
A string or list of strings to output line by line.
ERR
This is a friendlier wrapper to 'debug('ERR',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
ERROR
This is a friendlier wrapper to 'debug('ERR',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
WARN
This is a friendlier wrapper to 'debug('WARN',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
WARNING
This is a friendlier wrapper to 'debug('WARN',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
NOTICE
This is a friendlier wrapper to 'debug('NOTICE',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
INFO
This is a friendlier wrapper to 'debug('INFO',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
INFORMATION
This is a friendlier wrapper to 'debug('INFO',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
DEBUG
This is a friendlier wrapper to 'debug('DEBUG',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
DEBUGMAX
This is a friendlier wrapper to 'debug('DEBUGMAX',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
DEBUGWAIT
EXPERIMENTAL!!!! No whining.
This is a friendlier wrapper to 'debug('DEBUGWAIT',['message'])'. The level is inferred by its name.
- MESSAGE
-
Either a single string or a reference to a list of strings
INSTALLATION
To install this module, run the following commands:
perl Build.PL
./Build
./Build test
./Build install
OR you can use the old ExtUtils::MakeMaker method:
perl Makefile.PL
make
make test
make install
AUTHOR
Richard Kelsch <rich@rk-internet.com>
Copyright 2013 Richard Kelsch, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
VERSION
Version 0.34 (June 01, 2015)
BUGS
Please report any bugs or feature requests to bug-easydebug at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=EasyDebug. I will be notified, and then you'll 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 Debug::Easy
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
The author of Log::Fast. A very fine module, without which, this module would be much larger.
LICENSE AND COPYRIGHT
Copyright 2013 Richard Kelsch.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.