SYSLOG(3) SYSLOG(3) NAME syslog, openlog, closelog, setlogmask - control system log SYNOPSIS #include openlog(ident, logopt, facility) char *ident; syslog(priority, message, parameters ... ) char *message; closelog() setlogmask(maskpri) DESCRIPTION _S_y_s_l_o_g arranges to write _m_e_s_s_a_g_e onto the system log maintained by _s_y_s_‐ _l_o_g_d(8). The message is tagged with _p_r_i_o_r_i_t_y. The message looks like a _p_r_i_n_t_f(3) string except that %m is replaced by the current error mes‐ sage (collected from _e_r_r_n_o). A trailing newline is added if needed. This message will be read by _s_y_s_l_o_g_d(8) and written to the system con‐ sole, log files, or forwarded to _s_y_s_l_o_g_d on another host as appropri‐ ate. Priorities are encoded as a _f_a_c_i_l_i_t_y and a _l_e_v_e_l. The facility describes the part of the system generating the message. The level is selected from an ordered list: LOG_EMERG A panic condition. This is normally broadcast to all users. LOG_ALERT A condition that should be corrected immediately, such as a corrupted system database. LOG_CRIT Critical conditions, e.g., hard device errors. LOG_ERR Errors. LOG_WARNING Warning messages. LOG_NOTICE Conditions that are not error conditions, but should pos‐ sibly be handled specially. LOG_INFO Informational messages. LOG_DEBUG Messages that contain information normally of use only when debugging a program. If _s_y_s_l_o_g cannot pass the message to _s_y_s_l_o_g_d, it will attempt to write the message on _/_d_e_v_/_c_o_n_s_o_l_e if the LOG_CONS option is set (see below). If special processing is needed, _o_p_e_n_l_o_g can be called to initialize the log file. The parameter _i_d_e_n_t is a string that is prepended to every message. _L_o_g_o_p_t is a bit field indicating logging options. Cur‐ rent values for _l_o_g_o_p_t are: LOG_PID log the process id with each message: useful for identi‐ fying instantiations of daemons. LOG_CONS Force writing messages to the console if unable to send it to _s_y_s_l_o_g_d_. This option is safe to use in daemon processes that have no controlling terminal since _s_y_s_l_o_g will fork before opening the console. LOG_NDELAY Open the connection to _s_y_s_l_o_g_d immediately. Normally the open is delayed until the first message is logged. Use‐ ful for programs that need to manage the order in which file descriptors are allocated. LOG_NOWAIT Don’t wait for children forked to log messages on the console. This option should be used by processes that enable notification of child termination via SIGCHLD, as _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 parameter encodes a default facility to be assigned to all messages that do not have an explicit facility encoded: LOG_KERN Messages generated by the kernel. These cannot be gener‐ ated by any user processes. LOG_USER Messages generated by random user processes. This is the default facility identifier if none is specified. LOG_MAIL The mail system. LOG_DAEMON System daemons, such as _f_t_p_d(8), _r_o_u_t_e_d(8), etc. LOG_AUTH The authorization system: _l_o_g_i_n(1), _s_u(1), _g_e_t_t_y(8), etc. LOG_LPR The line printer spooling system: _l_p_r(1), _l_p_c(8), _l_p_d(8), etc. LOG_LOCAL0 Reserved for local use. Similarly for LOG_LOCAL1 through LOG_LOCAL7. _C_l_o_s_e_l_o_g can be used to close the log file. _S_e_t_l_o_g_m_a_s_k sets the log priority mask to _m_a_s_k_p_r_i and returns the previ‐ ous mask. Calls to _s_y_s_l_o_g with a priority not set in _m_a_s_k_p_r_i are rejected. The mask for an individual priority _p_r_i is calculated by the macro LOG_MASK(_p_r_i); the mask for all priorities up to and including _t_o_p_p_r_i is given by the macro LOG_UPTO(_t_o_p_p_r_i). The default allows all priorities to be logged. EXAMPLES syslog(LOG_ALERT, "who: internal error 23"); openlog("ftpd", LOG_PID, LOG_DAEMON); setlogmask(LOG_UPTO(LOG_ERR)); syslog(LOG_INFO, "Connection from host %d", CallingHost); syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); SEE ALSO logger(1), syslogd(8) 4.2 Berkeley Distribution May 15, 1986 SYSLOG(3)