Log::Any::Adapter::Carp - Simple adapter for logging via warnings
use Log::Any::Adapter;
# Minimal messages
Log::Any::Adapter->set('Carp', no_trace => 1, log_level => 'warn');
# Stack trace with every message
Log::Any::Adapter->set('Carp', full_trace => 1, log_level => 'debug');
This relatvely simple adapter for Log::Any is in many ways similar
to the builtin Log::Any::Adapter::Stderr, but instead of writing
messages directly to STDERR
, it uses Perl's "warn" in perlfunc
mechanism. This allows you to do things like generate stack traces,
or redirect the message via a $SIG{__WARN__}
hook, if you're using
that to handle diagnostic reporting from your application.
By default, the log message is generated by "carp" in Carp, so will have file and line information appended.
Log category is ignored. Other attributes that can be used to configure the adapter include:
-
log_level
The minimum level of message to log.
-
no_trace
If true, do not include any traceback or location information with the logged message. This causes a newline to be appended to the message, if it's not already there, and the result to be handed off to "warn" in perlfunc.
A true value supersedes any of the other traceback-modifying attributes described below.
Defaults to false.
-
full_trace
If true, the logged message is output with a full stack trace via "cluck" in Carp.
A true value supersedes any of the other traceback-modifying attributes except "no_trace".
Defaults to false.
-
skip_me
If true, this causes the package calling "set" in Log::Any::Adapter to be skipped when determining file and line information. This is probably not what you want in your application's mainline code, but may be useful if you're using a separate logging class, or logging messages from library. But rememeber that the application can override your settings if it chooses by calling "set" in Log::Any::Adapter.
Defaults to false.
-
skip_packages
Allows you to specify other packages to skip when "carp" in Carp is looking for location information.
If the value is an array reference, its contents are taken as package names to be excluded.
If the value is a compiled regular expression, then Carp::Clan is loaded and the content are used as a pattern for excluding packages. If Carp::Clan can't be loaded, a fatal error occurs. (Usage note: Carp::Clan's peculiar habit of prepending to the message the name of the function called from the last skipped package may limit its value for this particular purpose. At a minimum, you may wish to consider trimming off the prefix via a
$SIG{__WARN__}
hook.)If the value is anything else, it's just used as is. This means a simple package name will let you skip just that package, but any type of reference will probably not be useful. Subclasses may, of course, elect to extend this behavior, such as by accepting a code reference.
Defaults to empty.
None.
Are there, for certain, but have yet to be cataloged.
version 1.02
Charles Bailey [email protected]
Copyright (C) 2015 by Charles Bailey
This software may be used under the terms of the Artistic License or the GNU General Public License, as the user prefers.
The code incorporated into this package was originally written with United States federal funding as part of research work done by the author at the Children's Hospital of Philadelphia.