Configuring centralized logging from Perl scripts

Papertrail can accept logs from any Perl script. Here’s how.

Method A: Use local log file

Configure your script to log to a file as usual, then use remote_syslog2 to watch that file. Setup instructions.

Method B: Use 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:


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 => "<host>", port => 11111 });
syslog('info', 'something happened over here');

Change the port and host argument to match your Papertrail account, and $program and $sender as needed.