Sys::Syslog

use Sys::Syslog;                          # Misses setlogsock.
use Sys::Syslog qw(:DEFAULT setlogsock);  # Also gets setlogsock.

openlog($program, 'cons,pid', 'user');
syslog('info', 'this is another test');
syslog('mail|warning', 'this is a better test: %d', time());
closelog();

syslog('debug', 'this is the last test');

setlogsock('unix');
openlog("$program $$", 'ndelay', 'user');
syslog('info', 'problem was %m'); # %m == $! in syslogese
syslog('notice', 'fooprogram: this is really done');

setlogsock("unix");             # "inet" or "unix"
openlog("myprogname", $logopt, $facility);
syslog($priority, $format, @args);
$oldmask = setlogmask($mask_priority);
closelog();

The Sys::Syslog module acts like your C library's syslog (3) function, sending messages to your system log daemon, syslogd (8). It is especially useful in daemons and other programs lacking a terminal to receive diagnostic output, or for security-minded programs that want to produce a more lasting record of their actions (or someone else's actions). Supported functions are:

openlog IDENT, OPTLIST, FACILITY

Establishes a connection with your friendly syslog daemon. IDENT is the string to log messages under (like $0, your program name). OPTLIST is a string with comma-separated options such as "cons", "pid", and "ndelay". FACILITY is something like "auth", "daemon", "kern", "lpr", "mail", "news" or "user" for system programs, and one of "local0" .. "local7" for local ones. Further messages are logged using the given facility and identifying string. ...

Get Programming Perl, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.