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
11

NAME

13       closelog, openlog, setlogmask, syslog — control system log
14

SYNOPSIS

16       #include <syslog.h>
17
18       void closelog(void);
19       void openlog(const char *ident, int logopt, int facility);
20       int setlogmask(int maskpri);
21       void syslog(int priority, const char *message, ... /* arguments */);
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   A panic condition.
48
49       LOG_ALERT   A condition that should be corrected immediately, such as a
50                   corrupted system database.
51
52       LOG_CRIT    Critical conditions, such as hard device errors.
53
54       LOG_ERR     Errors.
55
56       LOG_WARNING
57                   Warning messages.
58
59       LOG_NOTICE  Conditions that are not  error  conditions,  but  that  may
60                   require special handling.
61
62       LOG_INFO    Informational messages.
63
64       LOG_DEBUG   Messages that contain information normally of use only when
65                   debugging a program.
66
67       The facility indicates the application or system  component  generating
68       the message. Possible facility values include:
69
70       LOG_USER    Messages  generated  by  arbitrary  processes.  This is the
71                   default facility identifier if none is specified.
72
73       LOG_LOCAL0  Reserved for local use.
74
75       LOG_LOCAL1  Reserved for local use.
76
77       LOG_LOCAL2  Reserved for local use.
78
79       LOG_LOCAL3  Reserved for local use.
80
81       LOG_LOCAL4  Reserved for local use.
82
83       LOG_LOCAL5  Reserved for local use.
84
85       LOG_LOCAL6  Reserved for local use.
86
87       LOG_LOCAL7  Reserved for local use.
88
89       The openlog() function shall set process attributes that affect  subse‐
90       quent  calls  to  syslog().   The  ident  argument  is a string that is
91       prepended to every  message.  The  logopt  argument  indicates  logging
92       options. Values for logopt are constructed by a bitwise-inclusive OR of
93       zero or more of the following:
94
95       LOG_PID     Log the process ID with each message. This  is  useful  for
96                   identifying specific processes.
97
98       LOG_CONS    Write messages to the system console if they cannot be sent
99                   to the logging facility. The syslog() function ensures that
100                   the  process  does not acquire the console as a controlling
101                   terminal in the process of writing the message.
102
103       LOG_NDELAY  Open the connection to the  logging  facility  immediately.
104                   Normally  the  open  is  delayed until the first message is
105                   logged. This is useful for programs that need to manage the
106                   order in which file descriptors are allocated.
107
108       LOG_ODELAY  Delay open until syslog() is called.
109
110       LOG_NOWAIT  Do  not wait for child processes that may have been created
111                   during the course  of  logging  the  message.  This  option
112                   should  be  used  by  processes that enable notification of
113                   child termination using SIGCHLD, since syslog() may  other‐
114                   wise  block  waiting  for  a  child  whose  exit status has
115                   already been collected.
116
117       The facility argument encodes a default facility to be assigned to  all
118       messages  that  do  not  have an explicit facility already encoded. The
119       initial default facility is LOG_USER.
120
121       The openlog() and syslog() functions may allocate a file descriptor. It
122       is not necessary to call openlog() prior to calling syslog().
123
124       The closelog() function shall close any open file descriptors allocated
125       by previous calls to openlog() or syslog().
126
127       The setlogmask() function shall set the log priority mask for the  cur‐
128       rent  process  to  maskpri and return the previous mask. If the maskpri
129       argument is 0, the current log mask is not modified. Calls by the  cur‐
130       rent  process  to  syslog() with a priority not set in maskpri shall be
131       rejected. The default log mask allows all priorities to  be  logged.  A
132       call to openlog() is not required prior to calling setlogmask().
133
134       Symbolic constants for use as values of the logopt, facility, priority,
135       and maskpri arguments are defined in the <syslog.h> header.
136

RETURN VALUE

138       The setlogmask() function shall return the previous log priority  mask.
139       The  closelog(),  openlog(),  and syslog() functions shall not return a
140       value.
141

ERRORS

143       No errors are defined.
144
145       The following sections are informative.
146

EXAMPLES

148   Using openlog()
149       The following example causes subsequent calls to syslog()  to  log  the
150       process  ID with each message, and to write messages to the system con‐
151       sole if they cannot be sent to the logging facility.
152
153           #include <syslog.h>
154
155           char *ident = "Process demo";
156           int logopt = LOG_PID | LOG_CONS;
157           int facility = LOG_USER;
158           ...
159           openlog(ident, logopt, facility);
160
161   Using setlogmask()
162       The following example causes subsequent calls  to  syslog()  to  accept
163       error messages, and to reject all other messages.
164
165           #include <syslog.h>
166
167           int result;
168           int mask = LOG_MASK (LOG_ERR);
169           ...
170           result = setlogmask(mask);
171
172   Using syslog
173       The following example sends the message "Thisisamessage" to the default
174       logging facility, marking the message as an error message generated  by
175       random processes.
176
177           #include <syslog.h>
178
179           char *message = "This is a message";
180           int priority = LOG_ERR | LOG_USER;
181           ...
182           syslog(priority, message);
183

APPLICATION USAGE

185       None.
186

RATIONALE

188       None.
189

FUTURE DIRECTIONS

191       None.
192

SEE ALSO

194       fprintf()
195
196       The Base Definitions volume of POSIX.1‐2008, <syslog.h>
197
199       Portions  of  this text are reprinted and reproduced in electronic form
200       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
201       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
202       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
203       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
204       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
205       event of any discrepancy between this version and the original IEEE and
206       The Open Group Standard, the original IEEE and The Open Group  Standard
207       is  the  referee document. The original Standard can be obtained online
208       at http://www.unix.org/online.html .
209
210       Any typographical or formatting errors that appear  in  this  page  are
211       most likely to have been introduced during the conversion of the source
212       files to man page format. To report such errors,  see  https://www.ker
213       nel.org/doc/man-pages/reporting_bugs.html .
214
215
216
217IEEE/The Open Group                  2013                         CLOSELOG(3P)
Impressum