Configuring centralized logging from Perl scripts

Papertrail can accept logs from any Perl script using either a local log file or the Sys::Syslog module.

Send log file with remote_syslog2

Configure your script to log to a file as usual, then transmit the log file to Papertrail using remote_syslog2. This does not require any modifications to the app.

Send events with Perl’s Sys::Syslog module

Perl can also send log messages directly to Papertrail using >= 0.28 of the Sys::Syslog module.

To determine which version of Sys:Syslog is installed:

$ perl -MSys::Syslog -e 'print "$Sys::Syslog::VERSION\n"'

To update it:

$ sudo perl -MCPAN -e shell
  # Accept all the defaults or modify as necessary
cpan> install Sys::Syslog
cpan> exit


The following sends a UDP syslog message:

use Sys::Syslog qw(:standard :macros setlogsock);  # standard functions & macros

$program = "PROGRAM";
$sender = "SENDER";
openlog("$program $sender", 'noeol,nonul');
setlogsock({ type => "udp", host => "", port => XXXXX });
syslog('info', 'something happened over here');

Replace logsN and XXXXX with details from one of your Papertrail log destinations, and $program and $sender as desired.