527 lines
9.9 KiB
HTML
527 lines
9.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SYSLOG</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SYSLOG</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
closelog, openlog, syslog, vsyslog - send messages to the system logger
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/syslog.h">syslog.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>void openlog(const char *</B><I>ident</I><B>, int </B><I>option</I><B>, int </B><I>facility</I><B>);</B>
|
|
|
|
<BR>
|
|
|
|
<B>void syslog(int </B><I>priority</I><B>, const char *</B><I>format</I><B>, ...);</B>
|
|
|
|
<BR>
|
|
|
|
<B>void closelog(void);</B>
|
|
|
|
<P>
|
|
|
|
<B>void vsyslog(int </B><I>priority</I><B>, const char *</B><I>format</I><B>, va_list </B><I>ap</I><B>);</B>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>vsyslog</B>():
|
|
|
|
<BR> Since glibc 2.19:
|
|
<BR> _DEFAULT_SOURCE
|
|
<BR> Glibc 2.19 and earlier:
|
|
<BR> _BSD_SOURCE
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>openlog()</H3>
|
|
|
|
<B>openlog</B>()
|
|
|
|
opens a connection to the system logger for a program.
|
|
<P>
|
|
|
|
The string pointed to by
|
|
<I>ident</I>
|
|
|
|
is prepended to every message, and is typically set to the program name.
|
|
If
|
|
<I>ident</I>
|
|
|
|
is NULL, the program name is used.
|
|
(POSIX.1-2008 does not specify the behavior when
|
|
<I>ident</I>
|
|
|
|
is NULL.)
|
|
<P>
|
|
|
|
The
|
|
<I>option</I>
|
|
|
|
argument specifies flags which control the operation of
|
|
<B>openlog</B>()
|
|
|
|
and subsequent calls to
|
|
<B>syslog</B>().
|
|
|
|
The
|
|
<I>facility</I>
|
|
|
|
argument establishes a default to be used if
|
|
none is specified in subsequent calls to
|
|
<B>syslog</B>().
|
|
|
|
The values that may be specified for
|
|
<I>option</I>
|
|
|
|
and
|
|
<I>facility</I>
|
|
|
|
are described below.
|
|
<P>
|
|
|
|
The use of
|
|
<B>openlog</B>()
|
|
|
|
is optional; it will automatically be called by
|
|
<B>syslog</B>()
|
|
|
|
if necessary, in which case
|
|
<I>ident</I>
|
|
|
|
will default to NULL.
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>syslog() and vsyslog()</H3>
|
|
|
|
<B>syslog</B>()
|
|
|
|
generates a log message, which will be distributed by
|
|
<B><A HREF="/cgi-bin/man/man2html?8+syslogd">syslogd</A></B>(8).
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>priority</I>
|
|
|
|
argument is formed by ORing together a
|
|
<I>facility</I>
|
|
|
|
value and a
|
|
<I>level</I>
|
|
|
|
value (described below).
|
|
If no
|
|
<I>facility</I>
|
|
|
|
value is ORed into
|
|
<I>priority</I>,
|
|
|
|
then the default value set by
|
|
<B>openlog</B>()
|
|
|
|
is used, or, if there was no preceding
|
|
<B>openlog</B>()
|
|
|
|
call, a default of
|
|
<B>LOG_USER</B>
|
|
|
|
is employed.
|
|
<P>
|
|
|
|
The remaining arguments are a
|
|
<I>format</I>,
|
|
|
|
as in
|
|
<B><A HREF="/cgi-bin/man/man2html?3+printf">printf</A></B>(3),
|
|
|
|
and any arguments required by the
|
|
<I>format</I>,
|
|
|
|
except that the two-character sequence
|
|
<B>%m</B>
|
|
|
|
will be replaced by
|
|
the error message string
|
|
<I>strerror</I>(<I>errno</I>).
|
|
|
|
The format string need not include a terminating newline character.
|
|
<P>
|
|
|
|
The function
|
|
<B>vsyslog</B>()
|
|
|
|
performs the same task as
|
|
<B>syslog</B>()
|
|
|
|
with the difference that it takes a set of arguments which have
|
|
been obtained using the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+stdarg">stdarg</A></B>(3)
|
|
|
|
variable argument list macros.
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>closelog()</H3>
|
|
|
|
<B>closelog</B>()
|
|
|
|
closes the file descriptor being used to write to the system logger.
|
|
The use of
|
|
<B>closelog</B>()
|
|
|
|
is optional.
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H3>Values for <I>option</I></H3>
|
|
|
|
The
|
|
<I>option</I>
|
|
|
|
argument to
|
|
<B>openlog</B>()
|
|
|
|
is a bit mask constructed by ORing together any of the following values:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>LOG_CONS</B>
|
|
|
|
<DD>
|
|
Write directly to the system console if there is an error while sending to
|
|
the system logger.
|
|
<DT id="2"><B>LOG_NDELAY</B>
|
|
|
|
<DD>
|
|
Open the connection immediately (normally, the connection is opened when
|
|
the first message is logged).
|
|
This may be useful, for example, if a subsequent
|
|
<B><A HREF="/cgi-bin/man/man2html?2+chroot">chroot</A></B>(2)
|
|
|
|
would make the pathname used internally by the logging facility unreachable.
|
|
<DT id="3"><B>LOG_NOWAIT</B>
|
|
|
|
<DD>
|
|
Don't wait for child processes that may have been created while logging
|
|
the message.
|
|
(The GNU C library does not create a child process, so this
|
|
option has no effect on Linux.)
|
|
<DT id="4"><B>LOG_ODELAY</B>
|
|
|
|
<DD>
|
|
The converse of
|
|
<B>LOG_NDELAY</B>;
|
|
|
|
opening of the connection is delayed until
|
|
<B>syslog</B>()
|
|
|
|
is called.
|
|
(This is the default, and need not be specified.)
|
|
<DT id="5"><B>LOG_PERROR</B>
|
|
|
|
<DD>
|
|
(Not in POSIX.1-2001 or POSIX.1-2008.)
|
|
Also log the message to
|
|
<I>stderr</I>.
|
|
|
|
<DT id="6"><B>LOG_PID</B>
|
|
|
|
<DD>
|
|
Include the caller's PID with each message.
|
|
|
|
</DL>
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Values for <I>facility</I></H3>
|
|
|
|
The
|
|
<I>facility</I>
|
|
|
|
argument is used to specify what type of program is logging the message.
|
|
This lets the configuration file specify that messages from different
|
|
facilities will be handled differently.
|
|
<DL COMPACT>
|
|
<DT id="7"><B>LOG_AUTH</B>
|
|
|
|
<DD>
|
|
security/authorization messages
|
|
<DT id="8"><B>LOG_AUTHPRIV</B>
|
|
|
|
<DD>
|
|
security/authorization messages (private)
|
|
<DT id="9"><B>LOG_CRON</B>
|
|
|
|
<DD>
|
|
clock daemon
|
|
(<B>cron</B> and <B>at</B>)
|
|
|
|
<DT id="10"><B>LOG_DAEMON</B>
|
|
|
|
<DD>
|
|
system daemons without separate facility value
|
|
<DT id="11"><B>LOG_FTP</B>
|
|
|
|
<DD>
|
|
ftp daemon
|
|
<DT id="12"><B>LOG_KERN</B>
|
|
|
|
<DD>
|
|
kernel messages (these can't be generated from user processes)
|
|
|
|
|
|
<DT id="13"><B>LOG_LOCAL0</B> through <B>LOG_LOCAL7</B>
|
|
|
|
<DD>
|
|
reserved for local use
|
|
<DT id="14"><B>LOG_LPR</B>
|
|
|
|
<DD>
|
|
line printer subsystem
|
|
<DT id="15"><B>LOG_MAIL</B>
|
|
|
|
<DD>
|
|
mail subsystem
|
|
<DT id="16"><B>LOG_NEWS</B>
|
|
|
|
<DD>
|
|
USENET news subsystem
|
|
<DT id="17"><B>LOG_SYSLOG</B>
|
|
|
|
<DD>
|
|
messages generated internally by
|
|
<B><A HREF="/cgi-bin/man/man2html?8+syslogd">syslogd</A></B>(8)
|
|
|
|
<DT id="18"><B>LOG_USER</B> (default)
|
|
|
|
<DD>
|
|
generic user-level messages
|
|
<DT id="19"><B>LOG_UUCP</B>
|
|
|
|
<DD>
|
|
UUCP subsystem
|
|
|
|
</DL>
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Values for <I>level</I></H3>
|
|
|
|
This determines the importance of the message.
|
|
The levels are, in order of decreasing importance:
|
|
<DL COMPACT>
|
|
<DT id="20"><B>LOG_EMERG</B>
|
|
|
|
<DD>
|
|
system is unusable
|
|
<DT id="21"><B>LOG_ALERT</B>
|
|
|
|
<DD>
|
|
action must be taken immediately
|
|
<DT id="22"><B>LOG_CRIT</B>
|
|
|
|
<DD>
|
|
critical conditions
|
|
<DT id="23"><B>LOG_ERR</B>
|
|
|
|
<DD>
|
|
error conditions
|
|
<DT id="24"><B>LOG_WARNING</B>
|
|
|
|
<DD>
|
|
warning conditions
|
|
<DT id="25"><B>LOG_NOTICE</B>
|
|
|
|
<DD>
|
|
normal, but significant, condition
|
|
<DT id="26"><B>LOG_INFO</B>
|
|
|
|
<DD>
|
|
informational message
|
|
<DT id="27"><B>LOG_DEBUG</B>
|
|
|
|
<DD>
|
|
debug-level message
|
|
</DL>
|
|
<P>
|
|
|
|
The function
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setlogmask">setlogmask</A></B>(3)
|
|
|
|
can be used to restrict logging to specified levels only.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>openlog</B>(),
|
|
|
|
<B>closelog</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>syslog</B>(),
|
|
|
|
<B>vsyslog</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe env locale<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
The functions
|
|
<B>openlog</B>(),
|
|
|
|
<B>closelog</B>(),
|
|
|
|
and
|
|
<B>syslog</B>()
|
|
|
|
(but not
|
|
<B>vsyslog</B>())
|
|
|
|
are specified in SUSv2, POSIX.1-2001, and POSIX.1-2008.
|
|
<P>
|
|
|
|
POSIX.1-2001 specifies only the
|
|
<B>LOG_USER</B>
|
|
|
|
and
|
|
<B>LOG_LOCAL*</B>
|
|
|
|
values for
|
|
<I>facility</I>.
|
|
|
|
However, with the exception of
|
|
<B>LOG_AUTHPRIV</B>
|
|
|
|
and
|
|
<B>LOG_FTP</B>,
|
|
|
|
the other
|
|
<I>facility</I>
|
|
|
|
values appear on most UNIX systems.
|
|
<P>
|
|
|
|
The
|
|
<B>LOG_PERROR</B>
|
|
|
|
value for
|
|
<I>option</I>
|
|
|
|
is not specified by POSIX.1-2001 or POSIX.1-2008, but is available
|
|
in most versions of UNIX.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The argument
|
|
<I>ident</I>
|
|
|
|
in the call of
|
|
<B>openlog</B>()
|
|
|
|
is probably stored as-is.
|
|
Thus, if the string it points to
|
|
is changed,
|
|
<B>syslog</B>()
|
|
|
|
may start prepending the changed string, and if the string
|
|
it points to ceases to exist, the results are undefined.
|
|
Most portable is to use a string constant.
|
|
<P>
|
|
|
|
Never pass a string with user-supplied data as a format,
|
|
use the following instead:
|
|
<P>
|
|
|
|
|
|
|
|
syslog(priority, "%s", string);
|
|
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+journalctl">journalctl</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?1+logger">logger</A></B>(1),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setlogmask">setlogmask</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+syslog.conf">syslog.conf</A></B>(5),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?8+syslogd">syslogd</A></B>(8)
|
|
|
|
<A NAME="lbAO"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="28"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="29"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="30"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="31"><A HREF="#lbAE">openlog()</A><DD>
|
|
<DT id="32"><A HREF="#lbAF">syslog() and vsyslog()</A><DD>
|
|
<DT id="33"><A HREF="#lbAG">closelog()</A><DD>
|
|
<DT id="34"><A HREF="#lbAH">Values for <I>option</I></A><DD>
|
|
<DT id="35"><A HREF="#lbAI">Values for <I>facility</I></A><DD>
|
|
<DT id="36"><A HREF="#lbAJ">Values for <I>level</I></A><DD>
|
|
</DL>
|
|
<DT id="37"><A HREF="#lbAK">ATTRIBUTES</A><DD>
|
|
<DT id="38"><A HREF="#lbAL">CONFORMING TO</A><DD>
|
|
<DT id="39"><A HREF="#lbAM">NOTES</A><DD>
|
|
<DT id="40"><A HREF="#lbAN">SEE ALSO</A><DD>
|
|
<DT id="41"><A HREF="#lbAO">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:58 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|