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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

147   Using openlog()
148       The following example causes subsequent calls to syslog()  to  log  the
149       process  ID with each message, and to write messages to the system con‐
150       sole if they cannot be sent to the logging facility.
151
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
166           #include <syslog.h>
167
168           int result;
169           int mask = LOG_MASK (LOG_ERR);
170           ...
171           result = setlogmask(mask);
172
173   Using syslog
174       The following example sends the message "Thisisamessage" to the default
175       logging facility, marking the message as an error message generated  by
176       random processes.
177
178
179           #include <syslog.h>
180
181           char *message = "This is a message";
182           int priority = LOG_ERR | LOG_USER;
183           ...
184           syslog(priority, message);
185

APPLICATION USAGE

187       None.
188

RATIONALE

190       None.
191

FUTURE DIRECTIONS

193       None.
194

SEE ALSO

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