2. Syslog Interface

The ‘(gamma syslog)’ module provides bindings for ‘syslog’ functions:

 
(use-modules ((gamma syslog)))
Scheme procedure: openlog tag option facility

Opens a connection to the system logger for Guile program. Arguments have the same meaning as in openlog(3):

tag

Syslog tag: a string that will be prepended to every message.

option

Flags that control the operation. A logical or (logior) of one or more of the following:

LOG_CONS

Write directly to system console if there is an error while sending to system logger.

LOG_NDELAY

Open the connection immediately (normally, the opening is delayed until when the first message is logged).

LOG_NOWAIT

Don't wait for child processes that may have been created while logging the message.

LOG_ODELAY

The converse of ‘LOG_NDELAY’; opening of the connection is delayed until syslog is called. This is the default.

LOG_PERROR

Print to stderr as well. This constant may be absent if the underlying implementation does not support it.

LOG_PID

Include PID with each message.

facility

Specifies what type of program is logging the message. The facility must be one of:

Facility Meaning
LOG_AUTH Security/authorization messages.
LOG_AUTHPRIV Same as LOG_AUTH.
LOG_CRON Clock daemon.
LOG_DAEMON System daemons without separate facility value.
LOG_FTP FTP daemon.
LOG_LOCAL0 through LOG_LOCAL7 Reserved for local use.
LOG_LPR Line printer subsystem.
LOG_MAIL Mail subsystem.
LOG_NEWS USENET news subsystem.
LOG_SYSLOG Messages generated internally by syslogd.
LOG_USER Generic user-level messages. This is the default.
LOG_UUCP UUCP subsystem.

Example:

 
(openlog "reader" (logior LOG_PID LOG_CONS) LOG_DAEMON)
Scheme procedure: syslog-tag

Returns the tag, used in the recent call to openlog.

Scheme procedure: syslog prio text

Distribute a message via syslogd. The text supplies the message text. The prio specifies priority of the message. Its value must be one of the following:

Priority Meaning
LOG_EMERG system is unusable
LOG_ALERT action must be taken immediately
LOG_CRIT critical conditions
LOG_ERR error conditions
LOG_WARNING warning conditions
LOG_NOTICE normal, but significant, condition
LOG_INFO informational message
LOG_DEBUG debug-level message

Example:

 
(syslog LOG_WARNING "This is a test message")

The priority argument may also be ‘OR’ed with a facility value, to override the one set by the openlog function, e.g.:

 
(syslog (logior LOG_DAEMON LOG_WARNING) "This is a test message")

It is common to use the format function to prepare the value of the text argument:

 
(syslog LOG_WARNING
   (format #f "operation reported: ~A" result))
Scheme procedure: open-syslog-port prio

Create a syslog port for the given priority. Syslog port is a special output port such that any writes to it are transferred to the syslog with the given priority. The port is line buffered. For example, the following code:

 
(set-current-output-port (open-syslog-port LOG_ERR))
(display "A test ")
(display "message")
(newline)

results in sending the string ‘A test message’ to the syslog priority LOG_ERR.

Scheme procedure: openlog?

Return #t if openlog was previously called.

Scheme procedure: closelog

Close the logging channel. The use of this function is optional.