1CLOSELOG(P) POSIX Programmer's Manual CLOSELOG(P)
2
3
4
6 closelog, openlog, setlogmask, syslog - control system log
7
9 #include <syslog.h>
10
11 void closelog(void);
12 void openlog(const char *ident, int logopt, int facility);
13 int setlogmask(int maskpri);
14 void syslog(int priority, const char *message, ... /* arguments */);
15
16
18 The syslog() function shall send a message to an implementation-defined
19 logging facility, which may log it in an implementation-defined system
20 log, write it to the system console, forward it to a list of users, or
21 forward it to the logging facility on another host over the network.
22 The logged message shall include a message header and a message body.
23 The message header contains at least a timestamp and a tag string.
24
25 The message body is generated from the message and following arguments
26 in the same manner as if these were arguments to printf(), except that
27 the additional conversion specification %m shall be recognized; it
28 shall convert no arguments, shall cause the output of the error message
29 string associated with the value of errno on entry to syslog(), and may
30 be mixed with argument specifications of the "%n$" form. If a complete
31 conversion specification with the m conversion specifier character is
32 not just %m , the behavior is undefined. A trailing <newline> may be
33 added if needed.
34
35 Values of the priority argument are formed by OR'ing together a sever‐
36 ity-level value and an optional facility value. If no facility value is
37 specified, the current default facility value is used.
38
39 Possible values of severity level include:
40
41 LOG_EMERG
42 A panic condition.
43
44 LOG_ALERT
45 A condition that should be corrected immediately, such as a cor‐
46 rupted system database.
47
48 LOG_CRIT
49 Critical conditions, such as hard device errors.
50
51 LOG_ERR
52 Errors.
53
54 LOG_WARNING
55
56 Warning messages.
57
58 LOG_NOTICE
59 Conditions that are not error conditions, but that may require
60 special handling.
61
62 LOG_INFO
63 Informational messages.
64
65 LOG_DEBUG
66 Messages that contain information normally of use only when
67 debugging a program.
68
69
70 The facility indicates the application or system component generating
71 the message. Possible facility values include:
72
73 LOG_USER
74 Messages generated by arbitrary processes. This is the default
75 facility identifier if none is specified.
76
77 LOG_LOCAL0
78 Reserved for local use.
79
80 LOG_LOCAL1
81 Reserved for local use.
82
83 LOG_LOCAL2
84 Reserved for local use.
85
86 LOG_LOCAL3
87 Reserved for local use.
88
89 LOG_LOCAL4
90 Reserved for local use.
91
92 LOG_LOCAL5
93 Reserved for local use.
94
95 LOG_LOCAL6
96 Reserved for local use.
97
98 LOG_LOCAL7
99 Reserved for local use.
100
101
102 The openlog() function shall set process attributes that affect subse‐
103 quent calls to syslog(). The ident argument is a string that is
104 prepended to every message. The logopt argument indicates logging
105 options. Values for logopt are constructed by a bitwise-inclusive OR of
106 zero or more of the following:
107
108 LOG_PID
109 Log the process ID with each message. This is useful for identi‐
110 fying specific processes.
111
112 LOG_CONS
113 Write messages to the system console if they cannot be sent to
114 the logging facility. The syslog() function ensures that the
115 process does not acquire the console as a controlling terminal
116 in the process of writing the message.
117
118 LOG_NDELAY
119 Open the connection to the logging facility immediately. Nor‐
120 mally the open is delayed until the first message is logged.
121 This is useful for programs that need to manage the order in
122 which file descriptors are allocated.
123
124 LOG_ODELAY
125 Delay open until syslog() is called.
126
127 LOG_NOWAIT
128 Do not wait for child processes that may have been created dur‐
129 ing the course of logging the message. This option should be
130 used by processes that enable notification of child termination
131 using SIGCHLD, since syslog() may otherwise block waiting for a
132 child whose exit status has already been collected.
133
134
135 The facility argument encodes a default facility to be assigned to all
136 messages that do not have an explicit facility already encoded. The
137 initial default facility is LOG_USER.
138
139 The openlog() and syslog() functions may allocate a file descriptor. It
140 is not necessary to call openlog() prior to calling syslog().
141
142 The closelog() function shall close any open file descriptors allocated
143 by previous calls to openlog() or syslog().
144
145 The setlogmask() function shall set the log priority mask for the cur‐
146 rent process to maskpri and return the previous mask. If the maskpri
147 argument is 0, the current log mask is not modified. Calls by the cur‐
148 rent process to syslog() with a priority not set in maskpri shall be
149 rejected. The default log mask allows all priorities to be logged. A
150 call to openlog() is not required prior to calling setlogmask().
151
152 Symbolic constants for use as values of the logopt, facility, priority,
153 and maskpri arguments are defined in the <syslog.h> header.
154
156 The setlogmask() function shall return the previous log priority mask.
157 The closelog(), openlog(), and syslog() functions shall not return a
158 value.
159
161 No errors are defined.
162
163 The following sections are informative.
164
166 Using openlog()
167 The following example causes subsequent calls to syslog() to log the
168 process ID with each message, and to write messages to the system con‐
169 sole if they cannot be sent to the logging facility.
170
171
172 #include <syslog.h>
173
174
175 char *ident = "Process demo";
176 int logopt = LOG_PID | LOG_CONS;
177 int facility = LOG_USER;
178 ...
179 openlog(ident, logopt, facility);
180
181 Using setlogmask()
182 The following example causes subsequent calls to syslog() to accept
183 error messages, and to reject all other messages.
184
185
186 #include <syslog.h>
187
188
189 int result;
190 int mask = LOG_MASK (LOG_ERR);
191 ...
192 result = setlogmask(mask);
193
194 Using syslog
195 The following example sends the message "This is a message" to the
196 default logging facility, marking the message as an error message gen‐
197 erated by random processes.
198
199
200 #include <syslog.h>
201
202
203 char *message = "This is a message";
204 int priority = LOG_ERR | LOG_USER;
205 ...
206 syslog(priority, message);
207
209 None.
210
212 None.
213
215 None.
216
218 printf() , the Base Definitions volume of IEEE Std 1003.1-2001, <sys‐
219 log.h>
220
222 Portions of this text are reprinted and reproduced in electronic form
223 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
224 -- Portable Operating System Interface (POSIX), The Open Group Base
225 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
226 Electrical and Electronics Engineers, Inc and The Open Group. In the
227 event of any discrepancy between this version and the original IEEE and
228 The Open Group Standard, the original IEEE and The Open Group Standard
229 is the referee document. The original Standard can be obtained online
230 at http://www.opengroup.org/unix/online.html .
231
232
233
234IEEE/The Open Group 2003 CLOSELOG(P)