Home

Advertisement

Previous Entry | Next Entry

Apr. 13th, 2009

  • 11:13 AM
default
This code appears in almost every one of my perl scripts, saved here for posterity.

use Sys::Syslog qw(:standard :macros);

our $SYSLOG_OPEN = 0;
our $PRINT_LOG = $ENV{PRINT_LOG} || 0;
our $PROGRAM_NAME = 'stupidwhateverd';

sub dout {
        unless($SYSLOG_OPEN) {
                openlog($PROGRAM_NAME,'ndelay,pid',LOG_DAEMON);
                $SYSLOG_OPEN = 1;
        }
        my $msg = shift;
        my $pri = shift || LOG_INFO;
        foreach my $line (split(/\n+/,$msg)) {
                syslog( $pri , '%s', $line);
                print STDERR "*** " . $PROGRAM_NAME . "[" . $$ . "]: " .
                        $line . "\n" if $PRINT_LOG;
        }
}