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