I know it works, but ...
[unix-history] / usr / src / lib / libc / gen / syslog.3
CommitLineData
609b3d57
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
ed6316b8 5.\" @(#)syslog.3 6.1 (Berkeley) %G%
609b3d57 6.\"
ed6316b8 7.TH SYSLOG 3 ""
609b3d57
KM
8.UC 5
9.SH NAME
ed6316b8 10syslog, openlog, closelog, setlogmask \- control system log
609b3d57
KM
11.SH SYNOPSIS
12.B "#include <syslog.h>
13.PP
ed6316b8 14.B "openlog(ident, logopt, maskpri)
609b3d57
KM
15.br
16.B "char *ident;
17.PP
18.B "syslog(priority, message, parameters ... )
19.br
20.B "char *message;
21.PP
22.B "closelog()
ed6316b8
KM
23.PP
24.B "setlogmask(maskpri)
609b3d57
KM
25.SH DESCRIPTION
26.I Syslog
ed6316b8 27arranges to write
609b3d57
KM
28.I message
29onto the system log maintained by
ed6316b8 30.IR syslogd (8).
609b3d57
KM
31The message is tagged with
32.IR priority .
33The message looks like a
34.IR printf (3)
35string except that
36.B %m
37is replaced by the current error message (collected from
38.IR errno ).
39A trailing newline is added if needed.
40This message will be read by
ed6316b8
KM
41.IR syslogd (8)
42and written to the system console, log files, or forwarded to
43.I syslogd
44on another host as appropriate.
45If
46.I syslog
47cannot pass the message to
48.I syslogd
49and the message is priority LOG_FAIL or higher,
50it attempts to write the message on
51.IR /dev/console.
609b3d57
KM
52.PP
53If special processing is needed,
54.I openlog
55can be called to initialize the log file.
ed6316b8 56The parameter
609b3d57 57.I ident
ed6316b8
KM
58is a string that is prepended to every message.
59.I Logopt
60is a bit field indicating logging options.
61Current values for
62.I logopt
63are:
64.IP LOG_PID \w'LOG_ODELAY'u+3
609b3d57
KM
65log the process id with each message:
66useful for identifying instantiations of daemons.
ed6316b8
KM
67.IP LOG_CONS \w'LOG_ODELAY'u+3
68Force writing error messages to the console if unable to send it to
69.I syslogd.
70This option is safe to use in daemon processes that have no controlling
71terminal since
72.I syslog
73will fork before opening the console.
74.IP LOG_ODELAY \w'LOG_ODELAY'u+3
75Delay opening the connection to
76.I syslogd
77until the first error occurs. Useful for programs that need to manage the
78order in which file descriptors are allocated.
79.PP
80The
81.I maskpri
82parameter is a mask for screening out low priority messages.
83Calls to
84.I syslog
85with a priority whose corresponding bit in
86.I maskpri
87is not set are ignored.
88The default allows all priorities to be logged.
609b3d57
KM
89.PP
90.I Closelog
91can be used to close the log file.
ed6316b8
KM
92.PP
93.I Setlogmask
94sets the log priority mask to
95.I maskpri
96and returns the previous mask.
97Priorities and masks of 0 are ignored.
609b3d57
KM
98.SH EXAMPLES
99.nf
100syslog(LOG_SALERT, "who: internal error 23");
101
ed6316b8 102openlog("serverftp", LOG_PID, 0);
609b3d57
KM
103syslog(LOG_INFO, "Connection from host %d", CallingHost);
104.fi
ed6316b8
KM
105.SH "SEE ALSO"
106syslogd(8)