Carp::Syslog - Send warn and die messages to syslog
# 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
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.
Carp::Syslog
The __WARN__ and __DIE__ signal handlers are overridden.
__WARN__
__DIE__
Calling cluck() or confess() will really fill up your logs.
Chris Grau mailto:cgrau@cpan.org
Copyright (c) 2011-2012, Chris Grau.
Sys::Syslog
To install Carp::Syslog, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Carp::Syslog
CPAN shell
perl -MCPAN -e shell install Carp::Syslog
For more information on module installation, please visit the detailed CPAN module installation guide.