.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Syslog 3pm" .TH Syslog 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Unix::Syslog \- Perl interface to the UNIX syslog(3) calls .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use Unix::Syslog qw(:macros); # Syslog macros \& use Unix::Syslog qw(:subs); # Syslog functions \& \& openlog $ident, $option, $facility; \& syslog $priority, $format, @formatargs; \& closelog; \& $oldmask = setlogmask $mask_priority; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module provides an interface to the system logger \fBsyslogd\fR(8) via Perl's XSUBs. The implementation attempts to resemble the native libc-functions of your system, so that anyone being familiar with \&\fIsyslog.h\fR should be able to use this module right away. .PP In contrary to \fBSys::Syslog\fR\|(3), this modules does not open a network connection to send the messages. This can help you to avoid opening security holes in your computer (see "FAQ"). .PP The subs imported by the tag \f(CW\*(C`macros\*(C'\fR are simply wrappers around the most important \f(CW\*(C`#defines\*(C'\fR in your system's C header file \&\fIsyslog.h\fR. The macros return integer values that are used to specify options, facilities and priorities in a more or less portable way. They also provide general information about your local syslog mechanism. Check \fBsyslog\fR\|(3) and your local \fIsyslog.h\fR for information about the macros, options and facilities available on your system. .PP The following functions are provided: .ie n .IP "openlog $ident, $option, $facility" 4 .el .IP "openlog \f(CW$ident\fR, \f(CW$option\fR, \f(CW$facility\fR" 4 .IX Item "openlog $ident, $option, $facility" opens a connection to the system logger. \fR\f(CI$ident\fR\fI\fR is an identifier string that \fBsyslogd\fR(8) prints into every message. It usually equals the process name. \fI\fR\f(CI$option\fR\fI\fR is an integer value that is the result of ORed options. \fI\fR\f(CI$facility\fR\fI\fR is an integer value that specifies the part of the system the message should be associated with (e.g. kernel message, mail subsystem). .ie n .IP "syslog $priority, $format, @formatargs" 4 .el .IP "syslog \f(CW$priority\fR, \f(CW$format\fR, \f(CW@formatargs\fR" 4 .IX Item "syslog $priority, $format, @formatargs" Generates a log message and passes it to the system logger. If \&\f(CWsyslog()\fR is called without calling \f(CWopenlog()\fR first, probably system dependent default values will be used as arguments for an implicit call to \f(CWopenlog()\fR. .Sp \&\fR\f(CI$priority\fR\fI\fR is an integer value that specifies the priority of the message. Alternatively \fI\fR\f(CI$priority\fR\fI\fR can be the ORed value of a priority and a facility. In that case a previously selected facility will be overridden. .Sp In the case that \f(CWsyslog()\fR is called without calling \f(CWopenlog()\fR first and \fIpriority\fR does not specify both a priority \fIand\fR a facility, a default facility will be used. This behaviour is most likely system dependent and the user should not rely on any particular value in that case. .Sp \&\fR\f(CI$format\fR\fI\fR is a format string in the style of \fBprintf\fR\|(3). Additionally to the usual printf directives \f(CW%m\fR can be specified in the string. It will be replaced implicitly by the contents of the Perl variable \f(CW$!\fR (\f(CW$ERRNO\fR). \fI\fR\f(CI@formatargs\fR\fI\fR is a list of values that the format directives will be replaced with subsequently. .IP closelog 4 .IX Item "closelog" closes the connection to the system logger. .ie n .IP "setlogmask $mask_priority" 4 .el .IP "setlogmask \f(CW$mask_priority\fR" 4 .IX Item "setlogmask $mask_priority" sets the priority mask and returns the old mask. Logging is enabled for the priorities indicated by the bits in the mask that are set and is disabled where the bits are not set. Macros are provided to specify valid and portable arguments to \f(CWsetlogmask()\fR. Usually the default log mask allows all messages to be logged. .ie n .IP "priorityname $priority" 4 .el .IP "priorityname \f(CW$priority\fR" 4 .IX Item "priorityname $priority" returns a string containing the name of \fR\f(CI$priority\fR\fI\fR as string. If this functionality has not been enabled at installation, the function returns \fIundef\fR. .ie n .IP "facilityname $facility" 4 .el .IP "facilityname \f(CW$facility\fR" 4 .IX Item "facilityname $facility" returns a string containing the name of \fR\f(CI$facility\fR\fI\fR as string. If this functionality has not been enabled at installation, the function returns \fIundef\fR. .PP \&\fBNOTE\fR: The behaviour of this module is system dependent. It is highly recommended to consult your system manual for available macros and the behaviour of the provided functions. .SH "RETURN VALUES" .IX Header "RETURN VALUES" The functions \fBopenlog()\fR, \fBsyslog()\fR and \fBcloselog()\fR return the undefined value. The function setlogmask returns the previous mask value. .SH EXAMPLES .IX Header "EXAMPLES" Open a channel to syslogd specifying an identifier (usually the process name) some options and the facility: \f(CW\*(C`openlog "test.pl", LOG_PID | LOG_PERROR, LOG_LOCAL7;\*(C'\fR .PP Generate log message of specified priority using a printf-type formatted string: \f(CW\*(C`syslog LOG_INFO, "This is message number %d", 42;\*(C'\fR .PP Set log priority mask to block all messages but those of priority \&\f(CW\*(C`LOG_DEBUG\*(C'\fR: \f(CW\*(C`$oldmask = setlogmask(LOG_MASK(LOG_DEBUG))\*(C'\fR .PP Set log priority mask to block all messages with a higher priority than \&\f(CW\*(C`LOG_ERR\*(C'\fR: \f(CW\*(C`$oldmask = setlogmask(LOG_UPTO(LOG_ERR))\*(C'\fR .PP Close channel to syslogd: \f(CW\*(C`closelog;\*(C'\fR .SH FAQ .IX Header "FAQ" .IP 1. 4 What is the benefit of using this module instead of Sys::Syslog? .Sp Sys::Syslog always opens a network connection to the syslog service. At least on Linux systems this may lead to some trouble, because .RS 4 .IP \(bu 4 Linux syslogd (from package sysklogd) does not listen to the network by default. Most people working on stand-alone machines (including me) didn't see any reason why to enable this option. Others didn't enable it for security reasons. .Sp OS-independent, some sysadmins may run a firewall on their network that blocks connections to port 514/udp. .IP \(bu 4 By default Linux syslogd doesn't forward messages which have already already received from the network to other log hosts. There are reasons not to enable this option unless it is really necessary. Looping messages resulting from a misconfiguration may break down your (log\-)system. .RE .RS 4 .Sp Peter Stamfest pointed out some other advantages of Unix::Syslog, I didn't came across my self. .IP \(bu 4 LOG_PERROR works. .IP \(bu 4 works with perl \-Tw without warnings and problems due to tainted data as it is the case for Sys::Syslog in some special applications. [Especially when running a script as root] .RE .RS 4 .RE .IP 2. 4 Well, is there any reason to use Sys::Syslog any longer? .Sp Yes! In contrary to Unix::Syslog, Sys::Syslog works even if you don't have a syslog daemon running on your system as long as you are connected to a log host via a network and have access to the \&\fIsyslog.h\fR header file of your log host to generate the initial files for Sys::Syslog (see \fBSys::Syslog\fR\|(3) for details). Unix::Syslog only logs to your local syslog daemon which in turn may be configured to distribute the message over the network. .IP 3. 4 Are calls to the functions provided by Unix::Syslog compatible to those of Sys::Syslog? .Sp Currently not. Sys::Syslog requires strings to specify many of the arguments to the functions, while Unix::Syslog uses numeric constants accessed via macros as defined in \fIsyslog.h\fR. Although the strings used by Sys::Syslog are also defined in \fIsyslog.h\fR, it seems that most people got used to the numeric arguments. I will implement the string based calls if there are enough people (\fR\f(CI$min_people\fR\fI\fR > 10**40) complaining about the lack of compatibility. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBsyslog\fR\|(3), \fBSys::Syslog\fR\|(3), \fBsyslogd\fR\|(8), \fBperl\fR\|(1) .SH AUTHOR .IX Header "AUTHOR" Marcus Harnisch