convert from ndbm(3) to db(3) interface
[unix-history] / usr / src / lib / libc / gen / syslog.3
CommitLineData
5442f39e
KB
1.\" Copyright (c) 1985 The Regents of the University of California.
2.\" All rights reserved.
609b3d57 3.\"
91cff1e1 4.\" %sccs.include.redist.man%
5442f39e 5.\"
4eabad57 6.\" @(#)syslog.3 6.16 (Berkeley) %G%
609b3d57 7.\"
ed6316b8 8.TH SYSLOG 3 ""
609b3d57
KM
9.UC 5
10.SH NAME
51dad0a9 11syslog, vsyslog, openlog, closelog, setlogmask \- control system log
609b3d57 12.SH SYNOPSIS
51dad0a9
KB
13.nf
14.ft B
15#include <syslog.h>
4eabad57 16void
51dad0a9
KB
17syslog(int priority, char *message, [, arg ] ... );
18
4eabad57
KB
19#include <varargs.h>
20void
51dad0a9
KB
21vsyslog(int priority, char *message, va_list args);
22
4eabad57 23void
51dad0a9
KB
24openlog(char *ident, int logopt, int facility);
25
4eabad57 26void
51dad0a9
KB
27closelog(void);
28
29setlogmask(int maskpri);
30.ft R
31.fi
609b3d57
KM
32.SH DESCRIPTION
33.I Syslog
51dad0a9 34writes
609b3d57 35.I message
51dad0a9
KB
36to the system message logger.
37The message will then be written to the system console, log files,
38logged-in users, or forwarded to other machines as appropriate (see
39.IR syslogd (8)).
40.PP
41The message is identical to a
609b3d57 42.IR printf (3)
51dad0a9
KB
43format string, except that ``%m'' is replaced by the current error
44message (as denoted by
45.IR errno ;
46see
47.IR strerror (3)).
48A trailing newline is added if none is present.
bbb3b705 49.PP
51dad0a9
KB
50.I Vsyslog
51is an alternate form in which the arguments have already been captured
52using the variable-length argument facilities of
53.IR varargs (3).
be78fd26 54.PP
51dad0a9
KB
55The message is tagged with
56.IR priority .
be78fd26
EA
57Priorities are encoded as a
58.I facility
59and a
60.IR level .
61The facility describes the part of the system
62generating the message.
51dad0a9
KB
63The level is selected from the following
64.B ordered
65(high to low) list:
3f4b96b5
KB
66.TP
67LOG_EMERG
68A panic condition.
69This is normally broadcast to all users.
70.TP
51dad0a9
KB
71LOG_ALERT
72A condition that should be corrected immediately, such as a corrupted
73system database.
74.TP
75LOG_CRIT
76Critical conditions, e.g., hard device errors.
77.TP
c262cc40 78LOG_ERR
be78fd26 79Errors.
c262cc40 80.TP
51dad0a9
KB
81LOG_WARNING
82Warning messages.
c262cc40
KB
83.TP
84LOG_NOTICE
be78fd26
EA
85Conditions that are not error conditions,
86but should possibly be handled specially.
c262cc40 87.TP
51dad0a9
KB
88LOG_INFO
89Informational messages.
90.TP
91LOG_DEBUG
92Messages that contain information
93normally of use only when debugging a program.
be78fd26 94.PP
51dad0a9
KB
95.I Openlog
96provides for more specialized processing of the messages sent
97by
ed6316b8 98.I syslog
51dad0a9
KB
99and
100.IR vsyslog .
ed6316b8 101The parameter
609b3d57 102.I ident
51dad0a9 103is a string that will be prepended to every message.
ed6316b8 104.I Logopt
51dad0a9
KB
105is a bit field specifying logging options, which is formed by
106.IR OR 'ing
107one or more of the following values:
c262cc40 108.TP
c262cc40 109LOG_CONS
51dad0a9
KB
110If
111.I syslog
112cannot pass the message to
113.I syslogd
114it will attempt to write the message to the console (``/dev/console'').
c262cc40
KB
115.TP
116LOG_NDELAY
6a71ef00 117Open the connection to
ed6316b8 118.I syslogd
0c9a57bf 119immediately.
51dad0a9
KB
120Normally the open is delayed until the first message is logged.
121Useful for programs that need to manage the order in which file
122descriptors are allocated.
c262cc40 123.TP
3f4b96b5 124LOG_PERROR
51dad0a9 125Write the message to standard error output as well to the system log.
3f4b96b5
KB
126.TP
127LOG_PID
51dad0a9
KB
128Log the process id with each message: useful for identifying
129instantiations of daemons.
ed6316b8
KM
130.PP
131The
be78fd26 132.I facility
6a71ef00 133parameter encodes a default facility to be assigned to all messages
be78fd26 134that do not have an explicit facility encoded:
c262cc40 135.TP
3f4b96b5
KB
136LOG_AUTH
137The authorization system:
138.IR login (1),
139.IR su (1),
140.IR getty (8),
141etc.
c262cc40 142.TP
51dad0a9
KB
143LOG_AUTHPRIV
144The same as LOG_AUTH, but logged to a file readable only by
145selected individuals.
146.TP
3f4b96b5
KB
147LOG_CRON
148The clock daemon.
c262cc40
KB
149.TP
150LOG_DAEMON
be78fd26 151System daemons, such as
a7aaa6ab 152.IR ftpd (8),
be78fd26 153.IR routed (8),
51dad0a9 154etc., that are not provided for explicitly by other facilities.
c262cc40 155.TP
3f4b96b5
KB
156LOG_KERN
157Messages generated by the kernel.
158These cannot be generated by any user processes.
c262cc40
KB
159.TP
160LOG_LPR
a4e75007
EA
161The line printer spooling system:
162.IR lpr (1),
163.IR lpc (8),
164.IR lpd (8),
165etc.
c262cc40 166.TP
3f4b96b5
KB
167LOG_MAIL
168The mail system.
169.TP
c262cc40
KB
170LOG_NEWS
171The network news system.
172.TP
3f4b96b5
KB
173LOG_SYSLOG
174Messages generated internally by
175.IR syslogd (8).
176.TP
177LOG_USER
178Messages generated by random user processes.
179This is the default facility identifier if none is specified.
180.TP
c262cc40
KB
181LOG_UUCP
182The uucp system.
183.TP
c262cc40 184LOG_LOCAL0
be78fd26
EA
185Reserved for local use.
186Similarly for LOG_LOCAL1 through LOG_LOCAL7.
609b3d57
KM
187.PP
188.I Closelog
189can be used to close the log file.
ed6316b8
KM
190.PP
191.I Setlogmask
192sets the log priority mask to
193.I maskpri
194and returns the previous mask.
be78fd26
EA
195Calls to
196.I syslog
6a71ef00 197with a priority not set in
be78fd26
EA
198.I maskpri
199are rejected.
6a71ef00
MK
200The mask for an individual priority
201.I pri
51dad0a9 202is calculated by the macro ``LOG_MASK(pri);''
6a71ef00
MK
203the mask for all priorities up to and including
204.I toppri
51dad0a9 205is given by the macro ``LOG_UPTO(toppri);''.
be78fd26 206The default allows all priorities to be logged.
609b3d57
KM
207.SH EXAMPLES
208.nf
51dad0a9 209.RS
be78fd26 210syslog(LOG_ALERT, "who: internal error 23");
609b3d57 211
be78fd26 212openlog("ftpd", LOG_PID, LOG_DAEMON);
6a71ef00 213setlogmask(LOG_UPTO(LOG_ERR));
609b3d57 214syslog(LOG_INFO, "Connection from host %d", CallingHost);
be78fd26
EA
215
216syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
51dad0a9 217.RE
609b3d57 218.fi
51dad0a9
KB
219.SH RETURNS
220The routines
4eabad57
KB
221.IR closelog ,
222.IR openlog ,
223.IR syslog
51dad0a9
KB
224and
225.I vsyslog
4eabad57 226return no value.
51dad0a9
KB
227.PP
228The routine
229.I setlogmask
4eabad57 230always returns the previous log mask level.
ed6316b8 231.SH "SEE ALSO"
51dad0a9 232logger(1), syslogd(8)