|
I want to use Log::Dispatch to log activity using a number of methods (screen, files, e-mail, etc).
If I encounter a certain error threashold (such as 'critical') I want the script to also "die". I would like Log::Dispatch to handle this for me anytime it dispatches a "critical" level error message.
I don't see a good way to do this. I could, prehaps, define a "critical" method which will "die" via a callback (as shown in my example below). But, besides being an ugly kludge, there's a functional problem with this (which I explain after this code):
#!/usr/bin/perl
use Log::Dispatch;
use Log::Dispatch::Screen ; use Log::Dispatch::File ;
my $dispatcher = Log::Dispatch->new;
$dispatcher ->add( Log::Dispatch::Screen ->new(
name => 'fubar',
min_level => 'critical',
callbacks => ${\sub {die "DIE\n"} ),
);
$dispatcher ->add( Log::Dispatch::File ->new(
name => 'file',
min_level => 'debug',
filename => '/tmp/junk.log' )
);
However, if I now do:
$dispatcher->critical("Oh no! The foo is barred");
It always calls the 'fubar' method FIRST (and dies). It won't ever call the lesser methods (such as 'file', 'screen', 'email', etc).
I want to call the lesser methods and THEN die (via Dispatcher). I know I could do this, of course:
$dispatcher->critical("Oh no! The foo is barred"); die;
But I really want Dispatcher to handle the "die" for me. Is there a good way to have Dispatcher call all other applicable methods and THEN "die" the script for me?
|