% This LaTeX document was generated using the LaTeX backend of PlDoc,
% The SWI-Prolog documentation system



\section{library(syslog): Unix syslog interface}

\label{sec:syslog}

\begin{tags}
\mtag{See also}- \predref{detach_IO}{1} to detach normal I/O of the process and remove it
from the process group. \\- \predref{fork}{1} to create a daemon process. \\- \verb$library(uid)$ to manage user identifiers (e.g., drop root
privileges).
\end{tags}

This library provides an interface to the Unix \verb$syslog()$ facility. The
interface is an almost direct translation of the POSIX syslog API, with
two additions:

\begin{itemize}
    \item \predref{syslog}{3} exploits \predref{format}{3} to format syslog messages
    \item The library integrates into \verb$library(debug)$ using
\qpredref{prolog}{debug_print_hook}{3}, where debug \textit{topics} are mapped to
syslog \textit{priorities} and remaining debug \textit{topics} are mapped
to the syslog \textit{priority} \const{debug}.
\end{itemize}

Note that this interface makes no attempt to abstract over logging
facilities of operating systems. We expect that such abstractions will
be implemented at the Prolog level using multiple integrations into
\verb$library(debug)$.\vspace{0.7cm}

\begin{description}
    \predicate[det]{openlog}{3}{+Ident:atom, +Options:list(atom), +Facility:atom}
Open system log. This predicate provides a direct interface into
the \verb$openlog()$ library call. If the library call is successful,
it runs \verb$at_halt(closelog)$ to ensure closing the system log on
clean exit.

\begin{arguments}
\arg{Ident} & prepended to every message, and is typically set
to the program name. \\
\arg{Options} & is a list of options. Values are corresponding
C options, after removing =LOG_= and translation to
lower case: \const{cons}, \const{ndelay}, \const{nowait}, \const{odelay},
\const{perror}, \const{pid}. \\
\arg{Facility} & is one of \const{auth}, \const{authpriv}, \const{cron}, \const{daemon},
\const{ftp}, \const{kern}, \const{local0} ... \const{local7}, \const{lpr}, \const{mail},
\const{news}, \const{syslog}, \const{user} or \const{uucp}. \\
\end{arguments}

    \predicate[det]{syslog}{2}{+Priority, +Message}
Send a message to the system log. Note that \predref{syslog}{2} implicitly
opens a connection to the system log if such a connection has
not been opened explicitly using \predref{openlog}{3}.

\begin{arguments}
\arg{Priority} & is one of \const{emerg}, \const{alert}, \const{crit}, \const{err},
\const{warning}, \const{notice}, \const{info} or \const{debug}. \\
\end{arguments}

    \predicate[det]{syslog}{3}{+Priority, +Format, +Args}
Send a formatted message to the system log if system logging is
opened using \predref{openlog}{3}. This predicate combined \predref{format}{3} with
\predref{syslog}{2}. If there is no open syslog connection, \predref{syslog}{3} calls
\predref{print_message}{2}.

    \predicate[det]{closelog}{0}{}
Close the system log.

\qpredicate[semidet,multifile]{prolog}{debug_print_hook}{3}{+Topic, +Format, +Args}Integration of \predref{debug}{3} with the syslog facility. If syslog is
enabled, \predref{debug}{3} is re-routed to use the syslog facilities. If
the \textit{topic} of the debug message matches one of the sylog
\textit{priority} values (see \predref{syslog}{2}), the message is sent with the
corresponding syslog priority. Otherwise it it sent with the
\const{debug} priority.
\end{description}

