NAME
Log::Fu - Simple logging module and interface with absolutely no required boilerplate - Now in COLOR!
DESCRIPTION
This is a simple interface for console logging. It provides a few functions, log_info
, log_debug
, log_warn
, log_crit
, and log_err
. They all take strings as arguments, and can take as many arguments as you so desire (so any concatenation is done for you).
A message is printed to standard error (or to $target if specified), prefixed with the filename, line number, and originating subroutine of the message. A format string might become available in the future
It is also possible to configure per-package logging parameters and level limitations. To do this, simply provide an option hashref when using the module, as shown in the synopsis. Available levels are: debug info warn err crit
Since this module uses a very plain and simple interface, it is easy to adjust your program to override these functions to wrap a more complex logging interface in the future.
There is very little boilerplate code for you to write, and it will normally just do its thing.
SYNOPSIS
use Miner::Logger { target => $some_filehandle, level => "info" };
log_debug("this is a debug level message");
log_info("this is an info-level message");
log_debugf("this is a %s", "format string");
EXPORTED SYMBOLS
- log_$LEVEL($message1,$message2...,) =item log_${LEVEL}f("put your %s here", "format string") logs a message to the target specified at import with $LEVEL priority.
-
the *f variants wrap around sprintf
- $SHUSH
-
Set this to a true value to silence all logging output
- $LINE_PREFIX
-
if set, each new line (not message) will be prefixed by this string.
- $USE_COLOR
-
Set to one if it's detected that your terminal/output device supports colors. You can always set this to 0 to turn it off, or set
LOG_FU_NO_COLOR
in your environment
PRIVATE SYMBOLS
These functions are subject to change and should not be used often. However they may be helpful in controlling logging when absolutely necessary
- Log::Fu::set_log_level($pkgname, $levelstr)
-
Sets $pkgname's logging level to $levelstr. $levelstr is one of err, debug, info, warn, crit etc.
- Log::Fu::start_syslog(@params)
-
Enables logging to syslog. @params are the options passed to "openlog" in Sys::Syslog
- Log::Fu::stop_syslog()
-
Stops logging to syslog
- _logger($numeric_level_constant, $level_display, $stack_offset, @messages)
-
$numeric_level_constant is a constant defined in this module, and is currently one of LOG_[WARN|DEBUG|ERR|INFO|CRIT]. $level_display is how to pretty-print the level.
A not-so-obvious parameter is $stack_offset, which is the amount of stack frames _logger should backtrack to get caller() info. All wrappers use a value of 1.
- log_$LEVEL_with_offset($offset, @messages)
-
like log_*, but allows to specify an offset. Useful in $SIG{__WARN__} or DIE functions
BUGS
None known
TODO
An optional (!!!) format string would be nice. Also, the ability to have functions like log_warnf instead of inserting log_warn sprintf.. statements all over (DONE in 0.05)
COPYRIGHT
Copyright 2011 M. Nunberg for Dynamite Data This module is dual-licensed as GPL/Perl Artistic. See README for details.