NAME

Carp::Syslog - Send warn and die messages to syslog

SYNOPSIS

# Defaults shown.
use Carp::Syslog { ident => $0, logopt => '', facility => 'user' };

warn '...';    # logs to user:warning

die '...';     # logs to user:err

# Shortcut for simplicity.
use Carp::Syslog 'user';

{
    no Carp::Syslog;

    warn '...';    # doesn't log to syslog
    die '...';     # ditto
}

# Also useful on the command line.
perl -MCarp::Syslog=user script.pl

DESCRIPTION

I got tired of writing this all the time:

use Sys::Syslog;
use File::Basename qw( basename );

BEGIN {
    openlog( basename($0), 'pid', 'local1' );
    $SIG{'__WARN__'} = sub { syslog( 'warning', @_ ); warn @_ };
    $SIG{'__DIE__'}  = sub { syslog( 'err', @_ ); die @_ };
}
END { closelog() }

Sure, there are modules like Log::Log4perl and Log::Dispatch, but those are overly complicated for quick, system administrator style scripts. The Carp::Syslog module allows, in one line (or less if used on the command line), to send all warn() and die() calls to the system's syslog.

CAVEATS

The __WARN__ and __DIE__ signal handlers are overridden.

Calling cluck() or confess() will really fill up your logs.

AUTHOR

Chris Grau mailto:cgrau@cpan.org

COPYRIGHT AND LICENSE

Copyright (c) 2011-2012, Chris Grau.

SEE ALSO

Sys::Syslog