xref: /csrg-svn/lib/libc/gen/syslog.3 (revision 20471)
Copyright (c) 1983 Regents of the University of California.
All rights reserved. The Berkeley software License Agreement
specifies the terms and conditions for redistribution.

@(#)syslog.3 6.1 (Berkeley) 05/15/85

SYSLOG 3 ""
C 5
NAME
syslog, openlog, closelog, setlogmask - control system log
SYNOPSIS
"#include <syslog.h>

"openlog(ident, logopt, maskpri)

"char *ident;

"syslog(priority, message, parameters ... )

"char *message;

"closelog()

"setlogmask(maskpri)

DESCRIPTION
Syslog arranges to write message onto the system log maintained by syslogd (8). The message is tagged with priority . The message looks like a printf (3) string except that %m is replaced by the current error message (collected from errno ). A trailing newline is added if needed. This message will be read by syslogd (8) and written to the system console, log files, or forwarded to syslogd on another host as appropriate. If syslog cannot pass the message to syslogd and the message is priority LOG_FAIL or higher, it attempts to write the message on /dev/console.

If special processing is needed, openlog can be called to initialize the log file. The parameter ident is a string that is prepended to every message. Logopt is a bit field indicating logging options. Current values for logopt are:

LOG_PID \w'LOG_ODELAY'u+3
log the process id with each message: useful for identifying instantiations of daemons.
LOG_CONS \w'LOG_ODELAY'u+3
Force writing error messages to the console if unable to send it to syslogd. This option is safe to use in daemon processes that have no controlling terminal since syslog will fork before opening the console.
LOG_ODELAY \w'LOG_ODELAY'u+3
Delay opening the connection to syslogd until the first error occurs. Useful for programs that need to manage the order in which file descriptors are allocated.

The maskpri parameter is a mask for screening out low priority messages. Calls to syslog with a priority whose corresponding bit in maskpri is not set are ignored. The default allows all priorities to be logged.

Closelog can be used to close the log file.

Setlogmask sets the log priority mask to maskpri and returns the previous mask. Priorities and masks of 0 are ignored.

EXAMPLES
syslog(LOG_SALERT, "who: internal error 23");

openlog("serverftp", LOG_PID, 0);
syslog(LOG_INFO, "Connection from host %d", CallingHost);
"SEE ALSO"
syslogd(8)