1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
'\" et
.TH CLOSELOG "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
closelog,
openlog,
setlogmask,
syslog
\(em control system log
.SH SYNOPSIS
.LP
.nf
#include <syslog.h>
.P
void closelog(void);
void openlog(const char *\fIident\fP, int \fIlogopt\fP, int \fIfacility\fP);
int setlogmask(int \fImaskpri\fP);
void syslog(int \fIpriority\fP, const char *\fImessage\fP, ... /* \fIarguments\fP */);
.fi
.SH DESCRIPTION
The
\fIsyslog\fR()
function shall send a message to an implementation-defined logging
facility, which may log it in an implementation-defined system log,
write it to the system console, forward it to a list of users, or
forward it to the logging facility on another host over the network.
The logged message shall include a message header and a message body.
The message header contains at least a timestamp and a tag string.
.P
The message body is generated from the
.IR message
and following arguments in the same manner as if these were arguments
to
\fIprintf\fR(),
except that the additional conversion specification
.BR %m
shall be recognized; it shall convert no arguments, shall cause the
output of the error message string associated with the value of
.IR errno
on entry to
\fIsyslog\fR(),
and may be mixed with argument specifications of the \fR"%\fIn\fR$"\fR
form. If a complete conversion specification with the
.BR m
conversion specifier character is not just
.BR %m ,
the behavior is undefined. A trailing
<newline>
may be added if needed.
.P
Values of the
.IR priority
argument are formed by OR'ing together a severity-level value and an
optional facility value. If no facility value is specified, the current
default facility value is used.
.P
Possible values of severity level include:
.IP LOG_EMERG 12
A panic condition.
.IP LOG_ALERT 12
A condition that should be corrected immediately, such as a corrupted
system database.
.IP LOG_CRIT 12
Critical conditions, such as hard device errors.
.IP LOG_ERR 12
Errors.
.IP LOG_WARNING 12
.br
Warning messages.
.IP LOG_NOTICE 12
Conditions that are not error conditions, but that may require special
handling.
.IP LOG_INFO 12
Informational messages.
.IP LOG_DEBUG 12
Messages that contain information normally of use only when debugging a
program.
.P
The facility indicates the application or system component generating
the message. Possible facility values include:
.IP LOG_USER 12
Messages generated by arbitrary processes. This is the default facility
identifier if none is specified.
.IP LOG_LOCAL0 12
Reserved for local use.
.IP LOG_LOCAL1 12
Reserved for local use.
.IP LOG_LOCAL2 12
Reserved for local use.
.IP LOG_LOCAL3 12
Reserved for local use.
.IP LOG_LOCAL4 12
Reserved for local use.
.IP LOG_LOCAL5 12
Reserved for local use.
.IP LOG_LOCAL6 12
Reserved for local use.
.IP LOG_LOCAL7 12
Reserved for local use.
.P
The
\fIopenlog\fR()
function shall set process attributes that affect subsequent calls to
\fIsyslog\fR().
The
.IR ident
argument is a string that is prepended to every message. The
.IR logopt
argument indicates logging options. Values for
.IR logopt
are constructed by a bitwise-inclusive OR of zero or more of the
following:
.IP LOG_PID 12
Log the process ID with each message. This is useful for identifying
specific processes.
.IP LOG_CONS 12
Write messages to the system console if they cannot be sent to the
logging facility. The
\fIsyslog\fR()
function ensures that the process does not acquire the console as a
controlling terminal in the process of writing the message.
.IP LOG_NDELAY 12
Open the connection to the logging facility immediately. Normally the
open is delayed until the first message is logged. This is useful for
programs that need to manage the order in which file descriptors are
allocated.
.IP LOG_ODELAY 12
Delay open until
\fIsyslog\fR()
is called.
.IP LOG_NOWAIT 12
Do not wait for child processes that may have been created during the
course of logging the message. This option should be used by processes
that enable notification of child termination using SIGCHLD, since
\fIsyslog\fR()
may otherwise block waiting for a child whose exit status has already
been collected.
.P
The
.IR facility
argument encodes a default facility to be assigned to all messages that
do not have an explicit facility already encoded. The initial default
facility is LOG_USER.
.P
The
\fIopenlog\fR()
and
\fIsyslog\fR()
functions may allocate a file descriptor. It is not necessary to call
\fIopenlog\fR()
prior to calling
\fIsyslog\fR().
.P
The
\fIcloselog\fR()
function shall close any open file descriptors allocated by previous
calls to
\fIopenlog\fR()
or
\fIsyslog\fR().
.P
The
\fIsetlogmask\fR()
function shall set the log priority mask for the current process to
.IR maskpri
and return the previous mask. If the
.IR maskpri
argument is 0, the current log mask is not modified. Calls by the
current process to
\fIsyslog\fR()
with a priority not set in
.IR maskpri
shall be rejected. The default log mask allows all priorities to be
logged. A call to
\fIopenlog\fR()
is not required prior to calling
\fIsetlogmask\fR().
.P
Symbolic constants for use as values of the
.IR logopt ,
.IR facility ,
.IR priority ,
and
.IR maskpri
arguments are defined in the
.IR <syslog.h>
header.
.SH "RETURN VALUE"
The
\fIsetlogmask\fR()
function shall return the previous log priority mask. The
\fIcloselog\fR(),
\fIopenlog\fR(),
and
\fIsyslog\fR()
functions shall not return a value.
.SH ERRORS
No errors are defined.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
.SS "Using openlog(\|)"
.P
The following example causes subsequent calls to
\fIsyslog\fR()
to log the process ID with each message, and to write messages to the
system console if they cannot be sent to the logging facility.
.sp
.RS 4
.nf
#include <syslog.h>
.P
char *ident = "Process demo";
int logopt = LOG_PID | LOG_CONS;
int facility = LOG_USER;
\&...
openlog(ident, logopt, facility);
.fi
.P
.RE
.SS "Using setlogmask(\|)"
.P
The following example causes subsequent calls to
\fIsyslog\fR()
to accept error messages, and to reject all other messages.
.sp
.RS 4
.nf
#include <syslog.h>
.P
int result;
int mask = LOG_MASK (LOG_ERR);
\&...
result = setlogmask(mask);
.fi
.P
.RE
.SS "Using syslog"
.P
The following example sends the message
.BR \(dqThis is a message\(dq
to the default logging facility, marking the message as an error
message generated by random processes.
.sp
.RS 4
.nf
#include <syslog.h>
.P
char *message = "This is a message";
int priority = LOG_ERR | LOG_USER;
\&...
syslog(priority, message);
.fi
.P
.RE
.SH "APPLICATION USAGE"
None.
.SH RATIONALE
None.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "\fIfprintf\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<syslog.h>\fP"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|