houseabsolute / Log-Dispatch

Dispatches messages to one or more outputs
https://metacpan.org/release/Log-Dispatch/
Other
12 stars 29 forks source link

Version 2.56 and Syslog.pm - unable to catch the die #20

Open targzeta opened 8 years ago

targzeta commented 8 years ago

Hi, on commit 13e4bcce46eddbfc8da30bc9b706cec5ceea7df6 you had ignored the die signal before any Sys::Syslog call (row 98 of the file Syslog.pm).

For me is critical to know if a message has been written by the syslogd (I have to produce legal logs).

See this little snippet of code:

use Log::Log4perl;

sub DIE_handler() {
  print 'DIE Handler - ' . "@_";

  exit(1);
}

sub main() {
  my $conf = q(
    log4perl.rootLogger=TRACE, syslog

    log4perl.appender.syslog = Log::Dispatch::Syslog
    log4perl.appender.syslog.facility = mail
    log4perl.appender.syslog.socket.type = tcp
    log4perl.appender.syslog.socket.port = 514
    log4perl.appender.syslog.layout = Log::Log4perl::Layout::SimpleLayout
  );

  Log::Log4perl::init(\$conf);

  my $logger = Log::Log4perl::get_logger();

  $SIG{__DIE__} = \&DIE_handler;
  $logger->trace('TRACE');

  print "Log message has been written!\n";
}

main();

My syslog appender is setted on TCP:514. Now, If I shut down the syslogd, with v2.54 I correctly have:

DIE Handler - no connection to syslog available
        - tcp connect: Connection refused at /opt/perl/lib/site_perl/5.16.3/Log/Dispatch/Syslog.pm line 109.

with v2.56 conversely:

Log message has been written!

As you can see, with the v2.56 my code says that the log message has been written, but it isn't true because the syslogd were down!

I think that this is a regression even because as the Sys::Syslog man page says, If we want to ignore the die, we can use the nofatal option:

nofatal - When set to true, openlog() and syslog() will only emit warnings instead of dying if the connection to the syslog can't be established.

Thank you in advance, Emanuele

autarch commented 8 years ago

This change came from #18 with some additional massaging. I think the idea was that logging often gets done in error handlers, and having the loggin itself throw an error set $@ can cause a lot of problems.