NAME
Log::WarnDie - Log standard Perl warnings and errors on a log handler
SYNOPSIS
use Log::WarnDie; # install to be used later
my $dispatcher = Log::Dispatch->new; # can be any dispatcher!
$dispatcher->add( Log::Dispatch::Foo->new( # whatever output you like
name => 'foo',
min_level => 'info',
) );
use Log::WarnDie $dispatcher; # activate later
Log::WarnDie->dispatcher( $dispatcher ); # same
warn "This is a warning"; # now also dispatched
die "Sorry it didn't work out"; # now also dispatched
no Log::WarnDie; # deactivate later
Log::WarnDie->dispatcher( undef ); # same
warn "This is a warning"; # no longer dispatched
die "Sorry it didn't work out"; # no longer dispatched
VERSION
This documentation describes version 0.05.
DESCRIPTION
The "Log::WarnDie" module offers a logging alternative for standard Perl core functions. This allows you to use the features of e.g. Log::Dispatch or Log::Log4Perl without having to make extensive changes to your source code.
When loaded, it installs a __WARN__ and __DIE__ handler and intercepts any output to STDERR. It also takes over the messaging functions of Carp. Without being further activated, the standard Perl logging functions continue to be executed: e.g. if you expect warnings to appear on STDERR, they will.
Then, when necessary, you can activate actual logging through e.g. Log::Dispatch by installing a log dispatcher. From then on, any warn, die, carp, croak, cluck, confess or print to the STDERR handle, will be logged using the Log::Dispatch logging dispatcher. Logging can be disabled and enabled at any time for critical sections of code.
LOG LEVELS
The following log levels are used:
warning
Any warn
, Carp::carp
or Carp::cluck
will generate a "warning" level message.
error
Any direct output to STDERR will generate an "error" level message.
critical
Any die
, Carp::croak
or Carp::confess
will generate a "critical" level message.
REQUIRED MODULES
Scalar::Util (1.08)
CAVEATS
The following caveats may apply to your situation.
Associated modules
Although a module such as Log::Dispatch is not listed as a prerequisite, the real use of this module only comes into view when such a module is installed. Please note that for testing this module, you will need the Log::Dispatch::Buffer module to also be available.
An alternate logger may be Log::Log4Perl, although this has not been tested by the author. Any object that provides a warning
, error
and critical
method, will operate with this module.
eval
In the current implementation of Perl, a __DIE__ handler is also called inside an eval. Whereas a normal die
would just exit the eval, the __DIE__ handler _will_ get called inside the eval. Which may or may not be what you want. To prevent the __DIE__ handler to be called inside eval's, add the following line to the eval block or string being evaluated:
local $SIG{__DIE__} = undef;
This disables the __DIE__ handler within the evalled block or string, and will automatically enable it again upon exit of the evalled block or string. Unfortunately there is no automatic way to do that for you.
AUTHOR
Elizabeth Mattijsen, <liz@dijkmat.nl>.
Please report bugs to <perlbugs@dijkmat.nl>.
COPYRIGHT
Copyright (c) 2004, 2007 Elizabeth Mattijsen <liz@dijkmat.nl>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.