```{index} single: Sys::Syslog ``` # Sys::Syslog ```{pperl-module-badges} Sys::Syslog ``` Messages to the system log: syslog(3) from Perl. This is Sys::Syslog 0.36; `Sys/Syslog.pm` is upstream's and is the interface. It sends a message by the first mechanism that works - the C library's syslog(3) ("native", these XSUBs), a UNIX socket, TCP, UDP, the console - and formats it, `printf`-style. ## Synopsis ```perl use Sys::Syslog qw(:standard :macros); openlog('myprog', 'ndelay,pid', LOG_USER); # ident, options, facility syslog(LOG_INFO, 'started with %d workers', 4); syslog('warning', 'disk %s at %d%%', '/var', 91); # levels by name too setlogmask(LOG_UPTO(LOG_NOTICE)); # drop info and debug closelog(); ``` ## The functions, written in Perl `:standard` exports the first four: - `openlog($ident, $options, $facility)` - name the program, choose options (`cons`, `ndelay`, `nofatal`, `perror`, `pid`), and the default facility (`LOG_USER`, `LOG_DAEMON`, `LOG_LOCAL0`..`LOG_LOCAL7`, ...). Optional: `syslog` opens with defaults. - `syslog($priority, $format, @args)` - one message; `$priority` is a level (`LOG_ERR`, `"err"`, ...), optionally with a facility (`"local0|info"`, `LOG_LOCAL0 | LOG_INFO`). - `setlogmask($mask)` - which levels get through; returns the old mask. - `closelog()`. - `setlogsock($type)` (`:extended`) - choose the mechanism: `native`, `unix`, `tcp`, `udp`, `stream`, `pipe`, `console`. `:macros` exports the levels (`LOG_EMERG` .. `LOG_DEBUG`), the facilities, the option flags (`LOG_PID`, `LOG_NDELAY`, ...), `LOG_MASK` and `LOG_UPTO`. ## Differences from upstream None: upstream's tests pass unchanged (t/81-xs-native/Sys-Syslog, the `upstream` files), and 010-constants.t checks every constant against perl 5.44. ## Functions ### Masks #### `LOG_MASK` The `setlogmask` bit of one level: `setlogmask(LOG_MASK(LOG_ERR))` lets only errors through. Exported with `:macros`. #### `LOG_UPTO` The `setlogmask` bits of a level and every more urgent one: `setlogmask(LOG_UPTO(LOG_WARNING))` drops notices, informational and debug messages. Exported with `:macros`. ### Priority values #### `LOG_FAC` The facility number of a combined priority value: `LOG_FAC(134)` is 16 for `LOG_LOCAL0` (whose value is 16 << 3). Not exported; call it as `Sys::Syslog::LOG_FAC`. #### `LOG_PRI` The level part of a combined priority value: `LOG_PRI(134)` is 6, `LOG_INFO`. Not exported; call it as `Sys::Syslog::LOG_PRI`. #### `LOG_MAKEPRI` A combined priority value from a facility and a level: `LOG_MAKEPRI(LOG_LOCAL0, LOG_INFO)` is 134. Not exported; call it as `Sys::Syslog::LOG_MAKEPRI`.