1syslog(3C) Standard C Library Functions syslog(3C)
2
3
4
6 syslog, openlog, closelog, setlogmask - control system log
7
9 #include <syslog.h>
10
11 void openlog(const char *ident, int logopt, int facility);
12
13
14 void syslog(int priority, const char *message, .../* arguments */);
15
16
17 void closelog(void);
18
19
20 int setlogmask(int maskpri);
21
22
24 The syslog() function sends a message to syslogd(1M), which, depending
25 on the configuration of /etc/syslog.conf, logs it in an appropriate
26 system log, writes it to the system console, forwards it to a list of
27 users, or forwards it to syslogd on another host over the network. The
28 logged message includes a message header and a message body. The mes‐
29 sage header consists of a facility indicator, a severity level indica‐
30 tor, a timestamp, a tag string, and optionally the process ID.
31
32
33 The message body is generated from the message and following arguments
34 in the same manner as if these were arguments to printf(3UCB), except
35 that occurrences of %m in the format string pointed to by the message
36 argument are replaced by the error message string associated with the
37 current value of errno. A trailing NEWLINE character is added if
38 needed.
39
40
41 Symbolic constants for use as values of the logopt, facility, priority,
42 and maskpri arguments are defined in the <syslog.h> header.
43
44
45 Values of the priority argument are formed by ORing together a severity
46 level value and an optional facility value. If no facility value is
47 specified, the current default facility value is used.
48
49
50 Possible values of severity level include, in decreasing order:
51
52 LOG_EMERG A panic condition. This is normally broadcast to all
53 users.
54
55
56 LOG_ALERT A condition that should be corrected immediately, such
57 as a corrupted system database.
58
59
60 LOG_CRIT Critical conditions, such as hard device errors.
61
62
63 LOG_ERR Errors.
64
65
66 LOG_WARNING Warning messages.
67
68
69 LOG_NOTICE Conditions that are not error conditions, but that may
70 require special handling.
71
72
73 LOG_INFO Informational messages.
74
75
76 LOG_DEBUG Messages that contain information normally of use only
77 when debugging a program.
78
79
80
81 The facility indicates the application or system component generating
82 the message. Possible facility values include:
83
84 LOG_KERN Messages generated by the kernel. These cannot be gener‐
85 ated by any user processes.
86
87
88 LOG_USER Messages generated by random user processes. This is the
89 default facility identifier if none is specified.
90
91
92 LOG_MAIL The mail system.
93
94
95 LOG_DAEMON System daemons, such as in.ftpd(1M).
96
97
98 LOG_AUTH The authentication / security / authorization system:
99 login(1), su(1M), getty(1M).
100
101
102 LOG_LPR The line printer spooling system: lpr(1B), lpc(1B).
103
104
105 LOG_NEWS Designated for the USENET network news system.
106
107
108 LOG_UUCP Designated for the UUCP system; it does not currently use
109 syslog().
110
111
112 LOG_CRON The cron/at facility; crontab(1), at(1), cron(1M).
113
114
115 LOG_AUDIT The audit facility, for example, auditd(1M).
116
117
118 LOG_LOCAL0 Designated for local use.
119
120
121 LOG_LOCAL1 Designated for local use.
122
123
124 LOG_LOCAL2 Designated for local use.
125
126
127 LOG_LOCAL3 Designated for local use.
128
129
130 LOG_LOCAL4 Designated for local use.
131
132
133 LOG_LOCAL5 Designated for local use.
134
135
136 LOG_LOCAL6 Designated for local use.
137
138
139 LOG_LOCAL7 Designated for local use.
140
141
142
143 The openlog() function sets process attributes that affect subsequent
144 calls to syslog(). The ident argument is a string that is prepended to
145 every message. The openlog() function uses the passed-in ident argument
146 directly, rather than making a private copy of it. The logopt argument
147 indicates logging options. Values for logopt are constructed by a bit‐
148 wise-inclusive OR of zero or more of the following:
149
150 LOG_PID Log the process ID with each message. This is useful for
151 identifying specific daemon processes (for daemons that
152 fork).
153
154
155 LOG_CONS Write messages to the system console if they cannot be
156 sent to syslogd(1M). This option is safe to use in daemon
157 processes that have no controlling terminal, since sys‐
158 log() forks before opening the console.
159
160
161 LOG_NDELAY Open the connection to syslogd(1M) immediately. Normally
162 the open is delayed until the first message is logged.
163 This is useful for programs that need to manage the order
164 in which file descriptors are allocated.
165
166
167 LOG_ODELAY Delay open until syslog() is called.
168
169
170 LOG_NOWAIT Do not wait for child processes that have been forked to
171 log messages onto the console. This option should be
172 used by processes that enable notification of child ter‐
173 mination using SIGCHLD, since syslog() may otherwise
174 block waiting for a child whose exit status has already
175 been collected.
176
177
178
179 The facility argument encodes a default facility to be assigned to all
180 messages that do not have an explicit facility already encoded. The
181 initial default facility is LOG_USER.
182
183
184 The openlog() and syslog() functions may allocate a file descriptor.
185 It is not necessary to call openlog() prior to calling syslog().
186
187
188 The closelog() function closes any open file descriptors allocated by
189 previous calls to openlog() or syslog().
190
191
192 The setlogmask() function sets the log priority mask for the current
193 process to maskpri and returns the previous mask. If the maskpri argu‐
194 ment is 0, the current log mask is not modified. Calls by the current
195 process to syslog() with a priority not set in maskpri are rejected.
196 The mask for an individual priority pri is calculated by the macro
197 LOG_MASK(pri); the mask for all priorities up to and including toppri
198 is given by the macro LOG_UPTO(toppri). The default log mask allows all
199 priorities to be logged.
200
202 The setlogmask() function returns the previous log priority mask. The
203 closelog(), openlog() and syslog() functions return no value.
204
206 No errors are defined.
207
209 Example 1 Example of LOG_ALERT message.
210
211
212 This call logs a message at priority LOG_ALERT:
213
214
215 syslog(LOG_ALERT, "who: internal error 23");
216
217
218
219
220 The FTP daemon ftpd would make this call to openlog() to indicate that
221 all messages it logs should have an identifying string of ftpd, should
222 be treated by syslogd(1M) as other messages from system daemons are,
223 should include the process ID of the process logging the message:
224
225
226 openlog("ftpd", LOG_PID, LOG_DAEMON);
227
228
229
230
231 Then it would make the following call to setlogmask() to indicate that
232 messages at priorities from LOG_EMERG through LOG_ERR should be logged,
233 but that no messages at any other priority should be logged:
234
235
236 setlogmask(LOG_UPTO(LOG_ERR));
237
238
239
240
241 Then, to log a message at priority LOG_INFO, it would make the follow‐
242 ing call to syslog:
243
244
245 syslog(LOG_INFO, "Connection from host %d", CallingHost);
246
247
248
249
250 A locally-written utility could use the following call to syslog() to
251 log a message at priority LOG_INFO to be treated by syslogd(1M) as
252 other messages to the facility LOG_LOCAL2 are:
253
254
255 syslog(LOG_INFO|LOG_LOCAL2, "error: %m");
256
257
258
260 See attributes(5) for descriptions of the following attributes:
261
262
263
264
265 ┌─────────────────────────────┬─────────────────────────────┐
266 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
267 ├─────────────────────────────┼─────────────────────────────┤
268 │Interface Stability │Committed │
269 ├─────────────────────────────┼─────────────────────────────┤
270 │MT-Level │Safe │
271 ├─────────────────────────────┼─────────────────────────────┤
272 │Standard │See standards(5). │
273 └─────────────────────────────┴─────────────────────────────┘
274
276 at(1), crontab(1), logger(1), login(1), lpc(1B), lpr(1B), auditd(1M),
277 cron(1M), getty(1M), in.ftpd(1M), su(1M), syslogd(1M), printf(3UCB),
278 syslog.conf(4), attributes(5), standards(5)
279
280
281
282SunOS 5.11 16 Mar 2009 syslog(3C)