CLOSELOG(3)                POSIX Programmer's Manual               CLOSELOG(3)



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

NNAAMMEE
       closelog, openlog, setlogmask, syslog -- control system log

SSYYNNOOPPSSIISS
       #include <syslog.h>

       void closelog(void);
       void openlog(const char *_i_d_e_n_t, int _l_o_g_o_p_t, int _f_a_c_i_l_i_t_y);
       int setlogmask(int _m_a_s_k_p_r_i);
       void syslog(int _p_r_i_o_r_i_t_y, const char *_m_e_s_s_a_g_e, ... /* _a_r_g_u_m_e_n_t_s */);

DDEESSCCRRIIPPTTIIOONN
       The _s_y_s_l_o_g() 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.

       The message body is generated from the _m_e_s_s_a_g_e and following arguments
       in the same manner as if these were arguments to _p_r_i_n_t_f(), except that
       the additional conversion specification %%mm shall be recognized; it
       shall convert no arguments, shall cause the output of the error message
       string associated with the value of _e_r_r_n_o on entry to _s_y_s_l_o_g(), and may
       be mixed with argument specifications of the "%_n$" form. If a complete
       conversion specification with the mm conversion specifier character is
       not just %%mm, the behavior is undefined. A trailing <newline> may be
       added if needed.

       Values of the _p_r_i_o_r_i_t_y 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.

       Possible values of severity level include:

       LOG_EMERG   A panic condition.

       LOG_ALERT   A condition that should be corrected immediately, such as a
                   corrupted system database.

       LOG_CRIT    Critical conditions, such as hard device errors.

       LOG_ERR     Errors.

       LOG_WARNING
                   Warning messages.

       LOG_NOTICE  Conditions that are not error conditions, but that may
                   require special handling.

       LOG_INFO    Informational messages.

       LOG_DEBUG   Messages that contain information normally of use only when
                   debugging a program.

       The facility indicates the application or system component generating
       the message. Possible facility values include:

       LOG_USER    Messages generated by arbitrary processes. This is the
                   default facility identifier if none is specified.

       LOG_LOCAL0  Reserved for local use.

       LOG_LOCAL1  Reserved for local use.

       LOG_LOCAL2  Reserved for local use.

       LOG_LOCAL3  Reserved for local use.

       LOG_LOCAL4  Reserved for local use.

       LOG_LOCAL5  Reserved for local use.

       LOG_LOCAL6  Reserved for local use.

       LOG_LOCAL7  Reserved for local use.

       The _o_p_e_n_l_o_g() function shall set process attributes that affect
       subsequent calls to _s_y_s_l_o_g().  The _i_d_e_n_t argument is a string that is
       prepended to every message. The _l_o_g_o_p_t argument indicates logging
       options. Values for _l_o_g_o_p_t are constructed by a bitwise-inclusive OR of
       zero or more of the following:

       LOG_PID     Log the process ID with each message. This is useful for
                   identifying specific processes.

       LOG_CONS    Write messages to the system console if they cannot be sent
                   to the logging facility. The _s_y_s_l_o_g() function ensures that
                   the process does not acquire the console as a controlling
                   terminal in the process of writing the message.

       LOG_NDELAY  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.

       LOG_ODELAY  Delay open until _s_y_s_l_o_g() is called.

       LOG_NOWAIT  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 _s_y_s_l_o_g() may
                   otherwise block waiting for a child whose exit status has
                   already been collected.

       The _f_a_c_i_l_i_t_y 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.

       The _o_p_e_n_l_o_g() and _s_y_s_l_o_g() functions may allocate a file descriptor. It
       is not necessary to call _o_p_e_n_l_o_g() prior to calling _s_y_s_l_o_g().

       The _c_l_o_s_e_l_o_g() function shall close any open file descriptors allocated
       by previous calls to _o_p_e_n_l_o_g() or _s_y_s_l_o_g().

       The _s_e_t_l_o_g_m_a_s_k() function shall set the log priority mask for the
       current process to _m_a_s_k_p_r_i and return the previous mask. If the _m_a_s_k_p_r_i
       argument is 0, the current log mask is not modified. Calls by the
       current process to _s_y_s_l_o_g() with a priority not set in _m_a_s_k_p_r_i shall be
       rejected. The default log mask allows all priorities to be logged. A
       call to _o_p_e_n_l_o_g() is not required prior to calling _s_e_t_l_o_g_m_a_s_k().

       Symbolic constants for use as values of the _l_o_g_o_p_t, _f_a_c_i_l_i_t_y, _p_r_i_o_r_i_t_y,
       and _m_a_s_k_p_r_i arguments are defined in the _<_s_y_s_l_o_g_._h_> header.

RREETTUURRNN VVAALLUUEE
       The _s_e_t_l_o_g_m_a_s_k() function shall return the previous log priority mask.
       The _c_l_o_s_e_l_o_g(), _o_p_e_n_l_o_g(), and _s_y_s_l_o_g() functions shall not return a
       value.

EERRRROORRSS
       No errors are defined.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   UUssiinngg ooppeennlloogg(())
       The following example causes subsequent calls to _s_y_s_l_o_g() 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.


           #include <syslog.h>

           char *ident = "Process demo";
           int logopt = LOG_PID | LOG_CONS;
           int facility = LOG_USER;
           ...
           openlog(ident, logopt, facility);

   UUssiinngg sseettllooggmmaasskk(())
       The following example causes subsequent calls to _s_y_s_l_o_g() to accept
       error messages, and to reject all other messages.


           #include <syslog.h>

           int result;
           int mask = LOG_MASK (LOG_ERR);
           ...
           result = setlogmask(mask);

   UUssiinngg ssyysslloogg
       The following example sends the message ""TThhiissisaamessage" to the default
       logging facility, marking the message as an error message generated by
       random processes.


           #include <syslog.h>

           char *message = "This is a message";
           int priority = LOG_ERR | LOG_USER;
           ...
           syslog(priority, message);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _f_p_r_i_n_t_f()

       The Base Definitions volume of POSIX.1-2017, <<ssyysslloogg..hh>>

CCOOPPYYRRIIGGHHTT
       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 .

       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 .



IEEE/The Open Group                  2017                          CLOSELOG(3)
