ualarm
[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.\"
a7aaa6ab 5.\" @(#)syslog.3 6.5 (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
78.I syslogd
be78fd26 79and the message is priority LOG_ERR or higher,
ed6316b8
KM
80it attempts to write the message on
81.IR /dev/console.
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
EA
104.IP LOG_NDELAY \w'LOG_WARNING'u+3
105Opening 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
KM
111order in which file descriptors are allocated.
112.PP
113The
be78fd26
EA
114.I facility
115parameter is encodes a default facility to be assigned to all messages
116that do not have an explicit facility encoded:
117.IP LOG_KERN \w'LOG_WARNING'u+3
118Messages generated by the kernel.
119These cannot be generated by any user processes.
120.IP LOG_USER \w'LOG_WARNING'u+3
121Messages generated by random user processes.
122This is the default if none is specified.
123.IP LOG_MAIL \w'LOG_WARNING'u+3
124The mail system.
125.IP LOG_DAEMON \w'LOG_WARNING'u+3
126System daemons, such as
a7aaa6ab 127.IR ftpd (8),
be78fd26
EA
128.IR routed (8),
129etc.
130.IP LOG_AUTH \w'LOG_WARNING'u+3
131The authorization system:
132.IR login (1),
133.IR su (1),
134.IR getty (8),
135etc.
a4e75007
EA
136.IP LOG_LPR \w'LOG_WARNING'u+3
137The line printer spooling system:
138.IR lpr (1),
139.IR lpc (8),
140.IR lpd (8),
141etc.
be78fd26
EA
142.IP LOG_LOCAL0 \w'LOG_WARNING'u+3
143Reserved for local use.
144Similarly for LOG_LOCAL1 through LOG_LOCAL7.
609b3d57
KM
145.PP
146.I Closelog
147can be used to close the log file.
ed6316b8
KM
148.PP
149.I Setlogmask
150sets the log priority mask to
151.I maskpri
152and returns the previous mask.
be78fd26
EA
153Calls to
154.I syslog
155with a priority lower than
156.I maskpri
157are rejected.
158The default allows all priorities to be logged.
609b3d57
KM
159.SH EXAMPLES
160.nf
be78fd26 161syslog(LOG_ALERT, "who: internal error 23");
609b3d57 162
be78fd26 163openlog("ftpd", LOG_PID, LOG_DAEMON);
609b3d57 164syslog(LOG_INFO, "Connection from host %d", CallingHost);
be78fd26
EA
165
166syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
609b3d57 167.fi
ed6316b8 168.SH "SEE ALSO"
be78fd26 169logger(1),
ed6316b8 170syslogd(8)