put reasonable header on it
[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.\"
6a71ef00 5.\" @(#)syslog.3 6.6 (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
be78fd26 14.B "openlog(ident, logopt, facility)
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.
be78fd26
EA
45.PP
46Priorities are encoded as a
47.I facility
48and a
49.IR level .
50The facility describes the part of the system
51generating the message.
52The level is selected from an ordered list:
53.IP LOG_EMERG \w'LOG_WARNING'u+3
54A panic condition.
55This is normally broadcast to all users.
56.IP LOG_ALERT \w'LOG_WARNING'u+3
57A condition that should be corrected immediately,
58such as a corrupted system database.
59.IP LOG_CRIT \w'LOG_WARNING'u+3
60Critical conditions,
61e.g., hard device errors.
62.IP LOG_ERR \w'LOG_WARNING'u+3
63Errors.
64.IP LOG_WARNING \w'LOG_WARNING'u+3
65Warning messages.
66.IP LOG_NOTICE \w'LOG_WARNING'u+3
67Conditions that are not error conditions,
68but should possibly be handled specially.
69.IP LOG_INFO \w'LOG_WARNING'u+3
70Informational messages.
71.IP LOG_DEBUG \w'LOG_WARNING'u+3
72Messages that contain information
73normally of use only when debugging a program.
74.PP
ed6316b8
KM
75If
76.I syslog
77cannot pass the message to
6a71ef00
MK
78.IR syslogd ,
79it will attempt to write the message on
80.I /dev/console
81if the LOG_CONS option is set (see below).
609b3d57
KM
82.PP
83If special processing is needed,
84.I openlog
85can be called to initialize the log file.
ed6316b8 86The parameter
609b3d57 87.I ident
ed6316b8
KM
88is a string that is prepended to every message.
89.I Logopt
90is a bit field indicating logging options.
91Current values for
92.I logopt
93are:
be78fd26 94.IP LOG_PID \w'LOG_WARNING'u+3
609b3d57
KM
95log the process id with each message:
96useful for identifying instantiations of daemons.
be78fd26
EA
97.IP LOG_CONS \w'LOG_WARNING'u+3
98Force writing messages to the console if unable to send it to
ed6316b8
KM
99.I syslogd.
100This option is safe to use in daemon processes that have no controlling
101terminal since
102.I syslog
103will fork before opening the console.
0c9a57bf 104.IP LOG_NDELAY \w'LOG_WARNING'u+3
6a71ef00 105Open the connection to
ed6316b8 106.I syslogd
0c9a57bf
EA
107immediately.
108Normally the open is delayed
be78fd26
EA
109until the first message is logged.
110Useful for programs that need to manage the
ed6316b8 111order in which file descriptors are allocated.
6a71ef00
MK
112.IP LOG_NOWAIT \w'LOG_WARNING'u+3
113Don't wait for children forked to log messages on the console.
114This option should be used by processes that enable notification
115of child termination via SIGCHLD, as
116.I syslog
117may otherwise block waiting for a child whose exit status has already
118been collected.
ed6316b8
KM
119.PP
120The
be78fd26 121.I facility
6a71ef00 122parameter encodes a default facility to be assigned to all messages
be78fd26
EA
123that do not have an explicit facility encoded:
124.IP LOG_KERN \w'LOG_WARNING'u+3
125Messages generated by the kernel.
126These cannot be generated by any user processes.
127.IP LOG_USER \w'LOG_WARNING'u+3
128Messages generated by random user processes.
6a71ef00 129This is the default facility identifier if none is specified.
be78fd26
EA
130.IP LOG_MAIL \w'LOG_WARNING'u+3
131The mail system.
132.IP LOG_DAEMON \w'LOG_WARNING'u+3
133System daemons, such as
a7aaa6ab 134.IR ftpd (8),
be78fd26
EA
135.IR routed (8),
136etc.
137.IP LOG_AUTH \w'LOG_WARNING'u+3
138The authorization system:
139.IR login (1),
140.IR su (1),
141.IR getty (8),
142etc.
a4e75007
EA
143.IP LOG_LPR \w'LOG_WARNING'u+3
144The line printer spooling system:
145.IR lpr (1),
146.IR lpc (8),
147.IR lpd (8),
148etc.
be78fd26
EA
149.IP LOG_LOCAL0 \w'LOG_WARNING'u+3
150Reserved for local use.
151Similarly for LOG_LOCAL1 through LOG_LOCAL7.
609b3d57
KM
152.PP
153.I Closelog
154can be used to close the log file.
ed6316b8
KM
155.PP
156.I Setlogmask
157sets the log priority mask to
158.I maskpri
159and returns the previous mask.
be78fd26
EA
160Calls to
161.I syslog
6a71ef00 162with a priority not set in
be78fd26
EA
163.I maskpri
164are rejected.
6a71ef00
MK
165The mask for an individual priority
166.I pri
167is calculated by the macro LOG_MASK(\fIpri\fP);
168the mask for all priorities up to and including
169.I toppri
170is given by the macro LOG_UPTO(\fItoppri\fP).
be78fd26 171The default allows all priorities to be logged.
609b3d57
KM
172.SH EXAMPLES
173.nf
be78fd26 174syslog(LOG_ALERT, "who: internal error 23");
609b3d57 175
be78fd26 176openlog("ftpd", LOG_PID, LOG_DAEMON);
6a71ef00 177setlogmask(LOG_UPTO(LOG_ERR));
609b3d57 178syslog(LOG_INFO, "Connection from host %d", CallingHost);
be78fd26
EA
179
180syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
609b3d57 181.fi
ed6316b8 182.SH "SEE ALSO"
be78fd26 183logger(1),
ed6316b8 184syslogd(8)