View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Elizabeth Mattijsen > Log-WarnDie-0.05 > Log::WarnDie



Annotate this POD


Open  1
View/Report Bugs
Module Version: 0.05   Source   Latest Release: Log-WarnDie-0.09


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.


Any direct output to STDERR will generate an "error" level message.


Any die, Carp::croak or Carp::confess will generate a "critical" level message.


 Scalar::Util (1.08)


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.


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, <>.

Please report bugs to <>.


Copyright (c) 2004, 2007 Elizabeth Mattijsen <>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: