Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Log::Log4perl syslog wall best practice

by codeacrobat (Chaplain)
on Mar 20, 2012 at 07:13 UTC ( #960540=perlquestion: print w/replies, xml ) Need Help??

codeacrobat has asked for the wisdom of the Perl Monks concerning the following question:

I am using Log::Log4perl with a Syslog appender in :easy mode. Currently I am flooded with Syslog messages whenever I LOGDIE LOGCROAK LOGEXIT in a script, as all of them log on FATAL severity.

I don't want the wall messages for my interactive scripts. What I am looking for is an easy tweak in Log::Log4perl or in rsyslog.conf to get rid of it.

The best I came up with is to make use of the $logger->error_die method, which is unfortunately not available in :easy mode.

There is also a ticket on rt.cpan.org to discuss the issue. https://rt.cpan.org/Public/Bug/Display.html?id=75781

Does anyone have a practical / better solution this?


print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Replies are listed 'Best First'.
Re: Log::Log4perl syslog wall best practice
by polettix (Vicar) on Mar 20, 2012 at 07:36 UTC
    After having looked at the explanation in the RT thread, I'd say that you can go for this small function:
    sub ERRORDIE { Log::Log4perl->get_logger->error_die(@_); }
    Put that in a module, use where applicable and you should be set without much complaining from cow-orkers.

    The fact is that you're trying to use the same hammer for very different nails, so you either need a different hammer (e.g. ERRORDIE above) or substitute the hammer on the fly (e.g. redefine LOGDIE/LOGCROAK/LOGEXIT). Personally, I'd leave LOGDIE its advertised semantic - i.e. raise a FATAL log message and exit with an error - and use a different function (e.g. ERRORDIE above) to do similar but different things.

    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Io ho capito... ma tu che hai detto?
Re: Log::Log4perl syslog wall best practice
by mull (Monk) on Mar 20, 2012 at 13:09 UTC

    I don't know I'm probably missing something here but FWIW I've had good luck with Sys::Syslog

    #!/usr/bin/perl -w # demonstration of writing to syslog from perl ## use strict; use warnings; use diagnostics; use Sys::Syslog qw(:DEFAULT setlogsock); my $fac = 'local1'; openlog( $0, 'cons,pid', $fac); syslog( 'notice', 'logging an event: %d', time); closelog();

      Wow, that is exactly the sort of logging bloat, that I try to get rid of.

      With Sys::Syslog you have full control over syslog that is not the point.

      I am looking for an integrated solution with the Log::Log4perl framework. I would like to use a tiny set of log4perl configuration files with good defaults and a mix of screen and syslog appenders. Inexperienced programmers should be able to quit a script with something like LOGDIE("could not do foo with bar"); (and possibly a stacktrace where it makes sense.). So far this all seems to work nicely. That is until I found out that syslog walls every FATAL to every open terminal.

      Now do I really have to rollback every LOGDIE/LOGCROAK to a lengthy ERROR() and exit statement or is there a tweak to shutup syslog or use an equivalent nonfatal LOGDIE.

      print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://960540]
Approved by lidden
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2021-09-19 09:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?