1CLOSELOG(3P)               POSIX Programmer's Manual              CLOSELOG(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       closelog, openlog, setlogmask, syslog - control system log
13

SYNOPSIS

15       #include <syslog.h>
16
17       void closelog(void);
18       void openlog(const char *ident, int logopt, int facility);
19       int setlogmask(int maskpri);
20       void syslog(int priority, const char *message, ... /* arguments */);
21
22

DESCRIPTION

24       The syslog() function shall send a message to an implementation-defined
25       logging  facility, which may log it in an implementation-defined system
26       log, write it to the system console, forward it to a list of users,  or
27       forward  it  to  the logging facility on another host over the network.
28       The logged message shall include a message header and a  message  body.
29       The message header contains at least a timestamp and a tag string.
30
31       The  message body is generated from the message and following arguments
32       in the same manner as if these were arguments to printf(), except  that
33       the  additional  conversion  specification  %m  shall be recognized; it
34       shall convert no arguments, shall cause the output of the error message
35       string associated with the value of errno on entry to syslog(), and may
36       be mixed with argument specifications of the "%n$" form.  If a complete
37       conversion  specification  with the m conversion specifier character is
38       not just %m, the behavior is undefined. A  trailing  <newline>  may  be
39       added if needed.
40
41       Values  of the priority argument are formed by OR'ing together a sever‐
42       ity-level value and an optional facility value. If no facility value is
43       specified, the current default facility value is used.
44
45       Possible values of severity level include:
46
47       LOG_EMERG
48              A panic condition.
49
50       LOG_ALERT
51              A condition that should be corrected immediately, such as a cor‐
52              rupted system database.
53
54       LOG_CRIT
55              Critical conditions, such as hard device errors.
56
57       LOG_ERR
58              Errors.
59
60       LOG_WARNING
61
62              Warning messages.
63
64       LOG_NOTICE
65              Conditions that are not error conditions, but that  may  require
66              special handling.
67
68       LOG_INFO
69              Informational messages.
70
71       LOG_DEBUG
72              Messages  that  contain  information  normally  of use only when
73              debugging a program.
74
75
76       The facility indicates the application or system  component  generating
77       the message. Possible facility values include:
78
79       LOG_USER
80              Messages  generated  by arbitrary processes. This is the default
81              facility identifier if none is specified.
82
83       LOG_LOCAL0
84              Reserved for local use.
85
86       LOG_LOCAL1
87              Reserved for local use.
88
89       LOG_LOCAL2
90              Reserved for local use.
91
92       LOG_LOCAL3
93              Reserved for local use.
94
95       LOG_LOCAL4
96              Reserved for local use.
97
98       LOG_LOCAL5
99              Reserved for local use.
100
101       LOG_LOCAL6
102              Reserved for local use.
103
104       LOG_LOCAL7
105              Reserved for local use.
106
107
108       The openlog() function shall set process attributes that affect  subse‐
109       quent  calls  to  syslog().  The  ident  argument  is  a string that is
110       prepended to every  message.  The  logopt  argument  indicates  logging
111       options. Values for logopt are constructed by a bitwise-inclusive OR of
112       zero or more of the following:
113
114       LOG_PID
115              Log the process ID with each message. This is useful for identi‐
116              fying specific processes.
117
118       LOG_CONS
119              Write  messages  to the system console if they cannot be sent to
120              the logging facility. The syslog()  function  ensures  that  the
121              process  does  not acquire the console as a controlling terminal
122              in the process of writing the message.
123
124       LOG_NDELAY
125              Open the connection to the logging  facility  immediately.  Nor‐
126              mally  the  open  is  delayed until the first message is logged.
127              This is useful for programs that need to  manage  the  order  in
128              which file descriptors are allocated.
129
130       LOG_ODELAY
131              Delay open until syslog() is called.
132
133       LOG_NOWAIT
134              Do  not wait for child processes that may have been created dur‐
135              ing the course of logging the message.  This  option  should  be
136              used  by processes that enable notification of child termination
137              using SIGCHLD, since syslog() may otherwise block waiting for  a
138              child whose exit status has already been collected.
139
140
141       The  facility argument encodes a default facility to be assigned to all
142       messages that do not have an explicit  facility  already  encoded.  The
143       initial default facility is LOG_USER.
144
145       The openlog() and syslog() functions may allocate a file descriptor. It
146       is not necessary to call openlog() prior to calling syslog().
147
148       The closelog() function shall close any open file descriptors allocated
149       by previous calls to openlog() or syslog().
150
151       The  setlogmask() function shall set the log priority mask for the cur‐
152       rent process to maskpri and return the previous mask.  If  the  maskpri
153       argument  is 0, the current log mask is not modified. Calls by the cur‐
154       rent process to syslog() with a priority not set in  maskpri  shall  be
155       rejected.   The  default log mask allows all priorities to be logged. A
156       call to openlog() is not required prior to calling setlogmask().
157
158       Symbolic constants for use as values of the logopt, facility, priority,
159       and maskpri arguments are defined in the <syslog.h> header.
160

RETURN VALUE

162       The  setlogmask() function shall return the previous log priority mask.
163       The closelog(), openlog(), and syslog() functions shall  not  return  a
164       value.
165

ERRORS

167       No errors are defined.
168
169       The following sections are informative.
170

EXAMPLES

172   Using openlog()
173       The  following  example  causes subsequent calls to syslog() to log the
174       process ID with each message, and to write messages to the system  con‐
175       sole if they cannot be sent to the logging facility.
176
177
178              #include <syslog.h>
179
180
181              char *ident = "Process demo";
182              int logopt = LOG_PID | LOG_CONS;
183              int facility = LOG_USER;
184              ...
185              openlog(ident, logopt, facility);
186
187   Using setlogmask()
188       The  following  example  causes  subsequent calls to syslog() to accept
189       error messages, and to reject all other messages.
190
191
192              #include <syslog.h>
193
194
195              int result;
196              int mask = LOG_MASK (LOG_ERR);
197              ...
198              result = setlogmask(mask);
199
200   Using syslog
201       The following example sends the message "This  is  a  message"  to  the
202       default  logging facility, marking the message as an error message gen‐
203       erated by random processes.
204
205
206              #include <syslog.h>
207
208
209              char *message = "This is a message";
210              int priority = LOG_ERR | LOG_USER;
211              ...
212              syslog(priority, message);
213

APPLICATION USAGE

215       None.
216

RATIONALE

218       None.
219

FUTURE DIRECTIONS

221       None.
222

SEE ALSO

224       printf(), the Base Definitions volume  of  IEEE Std 1003.1-2001,  <sys‐
225       log.h>
226
228       Portions  of  this text are reprinted and reproduced in electronic form
229       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
230       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
231       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
232       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
233       event of any discrepancy between this version and the original IEEE and
234       The  Open Group Standard, the original IEEE and The Open Group Standard
235       is the referee document. The original Standard can be  obtained  online
236       at http://www.opengroup.org/unix/online.html .
237
238
239
240IEEE/The Open Group                  2003                         CLOSELOG(3P)
Impressum