Log::WarnDie - Log standard Perl warnings and errors on a log handler
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
This documentation describes version 0.05.
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.
The following log levels are used:
Any warn, Carp::carp or Carp::cluck will generate a "warning" level message.
warn
Carp::carp
Carp::cluck
Any direct output to STDERR will generate an "error" level message.
Any die, Carp::croak or Carp::confess will generate a "critical" level message.
die
Carp::croak
Carp::confess
Scalar::Util (1.08)
The following caveats may apply to your situation.
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.
warning
error
critical
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.
Elizabeth Mattijsen, <liz@dijkmat.nl>.
Please report bugs to <perlbugs@dijkmat.nl>.
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.
To install Log::WarnDie, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::WarnDie
CPAN shell
perl -MCPAN -e shell install Log::WarnDie
For more information on module installation, please visit the detailed CPAN module installation guide.