Commit | Line | Data |
---|---|---|
5442f39e KB |
1 | .\" Copyright (c) 1985 The Regents of the University of California. |
2 | .\" All rights reserved. | |
609b3d57 | 3 | .\" |
5442f39e KB |
4 | .\" Redistribution and use in source and binary forms are permitted |
5 | .\" provided that the above copyright notice and this paragraph are | |
6 | .\" duplicated in all such forms and that any documentation, | |
7 | .\" advertising materials, and other materials related to such | |
8 | .\" distribution and use acknowledge that the software was developed | |
9 | .\" by the University of California, Berkeley. The name of the | |
10 | .\" University may not be used to endorse or promote products derived | |
11 | .\" from this software without specific prior written permission. | |
12 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
13 | .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
14 | .\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
15 | .\" | |
c262cc40 | 16 | .\" @(#)syslog.3 6.11 (Berkeley) %G% |
609b3d57 | 17 | .\" |
ed6316b8 | 18 | .TH SYSLOG 3 "" |
609b3d57 KM |
19 | .UC 5 |
20 | .SH NAME | |
38726b8e | 21 | syslog, openlog, closelog, setlogmask, vsyslog \- control system log |
609b3d57 KM |
22 | .SH SYNOPSIS |
23 | .B "#include <syslog.h> | |
24 | .PP | |
be78fd26 | 25 | .B "openlog(ident, logopt, facility) |
609b3d57 KM |
26 | .br |
27 | .B "char *ident; | |
28 | .PP | |
29 | .B "syslog(priority, message, parameters ... ) | |
30 | .br | |
bbb3b705 KB |
31 | .B "int priority; |
32 | .br | |
33 | .B "char *message; | |
34 | .PP | |
35 | .B "#include <varargs.h> | |
36 | .br | |
37 | .B "vsyslog(priority, message, args) | |
38 | .br | |
39 | .B "int priority; | |
40 | .br | |
609b3d57 | 41 | .B "char *message; |
bbb3b705 KB |
42 | .br |
43 | .B "va_list args; | |
609b3d57 KM |
44 | .PP |
45 | .B "closelog() | |
ed6316b8 KM |
46 | .PP |
47 | .B "setlogmask(maskpri) | |
609b3d57 KM |
48 | .SH DESCRIPTION |
49 | .I Syslog | |
ed6316b8 | 50 | arranges to write |
609b3d57 KM |
51 | .I message |
52 | onto the system log maintained by | |
ed6316b8 | 53 | .IR syslogd (8). |
609b3d57 KM |
54 | The message is tagged with |
55 | .IR priority . | |
56 | The message looks like a | |
57 | .IR printf (3) | |
58 | string except that | |
59 | .B %m | |
60 | is replaced by the current error message (collected from | |
61 | .IR errno ). | |
bbb3b705 KB |
62 | A trailing newline is added if needed. An alternate form, |
63 | in which the arguments have already been captured using the | |
64 | variable-length argument facilities of | |
65 | .IR varargs (3), | |
66 | is available under the name | |
67 | .IR vsyslog . | |
68 | .PP | |
609b3d57 | 69 | This message will be read by |
ed6316b8 KM |
70 | .IR syslogd (8) |
71 | and written to the system console, log files, or forwarded to | |
72 | .I syslogd | |
73 | on another host as appropriate. | |
be78fd26 EA |
74 | .PP |
75 | Priorities are encoded as a | |
76 | .I facility | |
77 | and a | |
78 | .IR level . | |
79 | The facility describes the part of the system | |
80 | generating the message. | |
81 | The level is selected from an ordered list: | |
c262cc40 KB |
82 | .TP |
83 | LOG_EMERG | |
be78fd26 EA |
84 | A panic condition. |
85 | This is normally broadcast to all users. | |
c262cc40 KB |
86 | .TP |
87 | LOG_ALERT | |
be78fd26 EA |
88 | A condition that should be corrected immediately, |
89 | such as a corrupted system database. | |
c262cc40 KB |
90 | .TP |
91 | LOG_CRIT | |
be78fd26 EA |
92 | Critical conditions, |
93 | e.g., hard device errors. | |
c262cc40 KB |
94 | .TP |
95 | LOG_ERR | |
be78fd26 | 96 | Errors. |
c262cc40 KB |
97 | .TP |
98 | LOG_WARNING | |
be78fd26 | 99 | Warning messages. |
c262cc40 KB |
100 | .TP |
101 | LOG_NOTICE | |
be78fd26 EA |
102 | Conditions that are not error conditions, |
103 | but should possibly be handled specially. | |
c262cc40 KB |
104 | .TP |
105 | LOG_INFO | |
be78fd26 | 106 | Informational messages. |
c262cc40 KB |
107 | .TP |
108 | LOG_DEBUG | |
be78fd26 EA |
109 | Messages that contain information |
110 | normally of use only when debugging a program. | |
111 | .PP | |
ed6316b8 KM |
112 | If |
113 | .I syslog | |
114 | cannot pass the message to | |
6a71ef00 MK |
115 | .IR syslogd , |
116 | it will attempt to write the message on | |
117 | .I /dev/console | |
118 | if the LOG_CONS option is set (see below). | |
609b3d57 KM |
119 | .PP |
120 | If special processing is needed, | |
121 | .I openlog | |
122 | can be called to initialize the log file. | |
ed6316b8 | 123 | The parameter |
609b3d57 | 124 | .I ident |
ed6316b8 KM |
125 | is a string that is prepended to every message. |
126 | .I Logopt | |
127 | is a bit field indicating logging options. | |
128 | Current values for | |
129 | .I logopt | |
130 | are: | |
c262cc40 KB |
131 | .TP |
132 | LOG_PID | |
b1d6afbf | 133 | Log the process id with each message: |
609b3d57 | 134 | useful for identifying instantiations of daemons. |
c262cc40 KB |
135 | .TP |
136 | LOG_PERROR | |
b1d6afbf | 137 | Write the message to stderr as well to the system log. |
c262cc40 KB |
138 | .TP |
139 | LOG_CONS | |
be78fd26 | 140 | Force writing messages to the console if unable to send it to |
ed6316b8 KM |
141 | .I syslogd. |
142 | This option is safe to use in daemon processes that have no controlling | |
143 | terminal since | |
144 | .I syslog | |
145 | will fork before opening the console. | |
c262cc40 KB |
146 | .TP |
147 | LOG_NDELAY | |
6a71ef00 | 148 | Open the connection to |
ed6316b8 | 149 | .I syslogd |
0c9a57bf EA |
150 | immediately. |
151 | Normally the open is delayed | |
be78fd26 EA |
152 | until the first message is logged. |
153 | Useful for programs that need to manage the | |
ed6316b8 | 154 | order in which file descriptors are allocated. |
c262cc40 KB |
155 | .TP |
156 | LOG_NOWAIT | |
6a71ef00 MK |
157 | Don't wait for children forked to log messages on the console. |
158 | This option should be used by processes that enable notification | |
159 | of child termination via SIGCHLD, as | |
160 | .I syslog | |
161 | may otherwise block waiting for a child whose exit status has already | |
162 | been collected. | |
ed6316b8 KM |
163 | .PP |
164 | The | |
be78fd26 | 165 | .I facility |
6a71ef00 | 166 | parameter encodes a default facility to be assigned to all messages |
be78fd26 | 167 | that do not have an explicit facility encoded: |
c262cc40 KB |
168 | .TP |
169 | LOG_KERN | |
be78fd26 EA |
170 | Messages generated by the kernel. |
171 | These cannot be generated by any user processes. | |
c262cc40 KB |
172 | .TP |
173 | LOG_USER | |
be78fd26 | 174 | Messages generated by random user processes. |
6a71ef00 | 175 | This is the default facility identifier if none is specified. |
c262cc40 KB |
176 | .TP |
177 | LOG_MAIL | |
be78fd26 | 178 | The mail system. |
c262cc40 KB |
179 | .TP |
180 | LOG_DAEMON | |
be78fd26 | 181 | System daemons, such as |
a7aaa6ab | 182 | .IR ftpd (8), |
be78fd26 | 183 | .IR routed (8), |
c262cc40 KB |
184 | etc, that are not provided for explicitly by other facilities. |
185 | .TP | |
186 | LOG_AUTH | |
be78fd26 EA |
187 | The authorization system: |
188 | .IR login (1), | |
189 | .IR su (1), | |
190 | .IR getty (8), | |
191 | etc. | |
c262cc40 KB |
192 | .TP |
193 | LOG_SYSLOG | |
194 | Messages generated internally by | |
195 | .IR syslogd (8). | |
196 | .TP | |
197 | LOG_LPR | |
a4e75007 EA |
198 | The line printer spooling system: |
199 | .IR lpr (1), | |
200 | .IR lpc (8), | |
201 | .IR lpd (8), | |
202 | etc. | |
c262cc40 KB |
203 | .TP |
204 | LOG_NEWS | |
205 | The network news system. | |
206 | .TP | |
207 | LOG_UUCP | |
208 | The uucp system. | |
209 | .TP | |
210 | LOG_CRON | |
211 | The clock daemon. | |
212 | .TP | |
213 | LOG_LOCAL0 | |
be78fd26 EA |
214 | Reserved for local use. |
215 | Similarly for LOG_LOCAL1 through LOG_LOCAL7. | |
609b3d57 KM |
216 | .PP |
217 | .I Closelog | |
218 | can be used to close the log file. | |
ed6316b8 KM |
219 | .PP |
220 | .I Setlogmask | |
221 | sets the log priority mask to | |
222 | .I maskpri | |
223 | and returns the previous mask. | |
be78fd26 EA |
224 | Calls to |
225 | .I syslog | |
6a71ef00 | 226 | with a priority not set in |
be78fd26 EA |
227 | .I maskpri |
228 | are rejected. | |
6a71ef00 MK |
229 | The mask for an individual priority |
230 | .I pri | |
231 | is calculated by the macro LOG_MASK(\fIpri\fP); | |
232 | the mask for all priorities up to and including | |
233 | .I toppri | |
234 | is given by the macro LOG_UPTO(\fItoppri\fP). | |
be78fd26 | 235 | The default allows all priorities to be logged. |
609b3d57 KM |
236 | .SH EXAMPLES |
237 | .nf | |
be78fd26 | 238 | syslog(LOG_ALERT, "who: internal error 23"); |
609b3d57 | 239 | |
be78fd26 | 240 | openlog("ftpd", LOG_PID, LOG_DAEMON); |
6a71ef00 | 241 | setlogmask(LOG_UPTO(LOG_ERR)); |
609b3d57 | 242 | syslog(LOG_INFO, "Connection from host %d", CallingHost); |
be78fd26 EA |
243 | |
244 | syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); | |
609b3d57 | 245 | .fi |
ed6316b8 | 246 | .SH "SEE ALSO" |
be78fd26 | 247 | logger(1), |
ed6316b8 | 248 | syslogd(8) |