Author image Robert Acock 🤞🌏
and 1 contributors


Log::ForPerl - Log standard Perl warnings and errors


 use Log::ForPerl; # install to be used later

 my $dispatcher = Log::Dispatch->new;
 $dispatcher->add( Log::ForPerl->new(
  name      => 'foo',
  min_level => 'info',
 ) );

 use Log::ForPerl $dispatcher; # activate later

 Log::ForPerl->dispatcher( $dispatcher ); # same

 warn "This is a warning"; # now also dispatched
 die "Sorry it didn't work out"; # now also dispatched

 no Log::ForPerl; # deactivate later

 Log::ForPerl->dispatcher( undef ); # same

 warn "This is a warning"; # no longer dispatched
 die "Sorry it didn't work out"; # no longer dispatched


The "Log::ForPerl" module offers a logging alternative for standard Perl core functions. This allows you to use the features of Log::Dispatch without having to make extensive changes to your source code.

When loaded, it installs a __WARN__ and __DIE__ handler. It also takes over the messaging functions of Carp. Without being further activated, the standard Perl logging functions continue to be done.

Then, when necessary, you can activate actual logging through Log::Dispatch by installing a log dispatcher. From then on, any warn, die, carp, croak, cluck or confess 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 caveats may apply to your situation.

Associated modules

Although Log::Dispatch is not listed as a prerequisite, the real use of this module only comes into view when that module is installed. Please note that for testing this module, you will need the Log::Dispatch::Buffer module to also be available.


In the current implementation of Perl, a __DIE__ handler is also called inside an eval. Whereas a normal


Elizabeth Mattijsen, <>.

Please report bugs to <>.


Copyright (c) 2004 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.