p
The message is identical to a
.Xr printf 3
format string, except that
.Ql %m
is replaced by the current error
message.
(As denoted by the global variable
.Va errno ;
see
.Xr strerror 3 . )
A trailing newline is added if none is present.
shouldn't the newline statement be removed?
when logging through a socket a newline is
not added nor is it required. -- ms
p The .Fn syslog_r function is a multithread-safe version of the .Fn syslog function. It takes a pointer to a .Fa syslog_data structure which is used to store information. This parameter must be initialized before .Fn syslog_r is called. The .Dv SYSLOG_DATA_INIT constant is used for this purpose. The .Fa syslog_data structure and the .Dv SYSLOG_DATA_INIT constant are defined as: d -literal -offset indent struct syslog_data { int log_file; int connected; int opened; int log_stat; const char *log_tag; int log_fac; int log_mask; }; #define SYSLOG_DATA_INIT { \e .log_file = -1, \e .log_fac = LOG_USER, \e .log_mask = 0xff, \e } .Ed
p The structure is composed of the following elements: l -tag -width connected -offset indent t Va log_file contains the file descriptor of the file where the message is logged t Va connected indicates if connect has been done t Va opened indicates if .Fn openlog_r has been called t Va log_stat status bits, set by .Fn openlog_r t Va log_tag string to tag the entry with t Va log_fac facility code t Va log_mask mask of priorities to be logged .El
p The .Fn syslog_ss is the async-signal-safe version of .Fn syslog_r and is also multithread-safe. It has the following limitations: l -enum -offset indent t The format string cannot contain multi-byte character sequences. t Positional .Xr printf 3 arguments are not supported. t Floating point formats are not supported and print .Dq UNK . t The time of the event is not sent to .Xr syslogd 8 . t The error string in the %m format is not printed symbolically but as .Dq Error %d . .El
p For more information about async-signal-safe functions and signal handlers, see .Xr signal 7 .
p Similarly .Fn vsyslog_ss is the async-signal-safe version of .Fn vsyslog_r . Same for .Fn syslogp_ss and .Fn syslogp_r , and finally .Fn vsyslogp_ss and .Fn vsyslogp_r .
p The .Fn vsyslog function is an alternative form in which the arguments have already been captured using the variable-length argument facilities of .Xr stdarg 3 .
p The .Fn syslogp variants take additional arguments which correspond to new fields in the syslog-protocol message format. All three arguments are evaluated as .Xr printf 3 format strings and any of them can be .Dv NULL . This enables applications to use message IDs, structured data, and UTF-8 encoded content in messages.
p The message is tagged with .Fa priority . Priorities are encoded as a .Fa facility and a .Em level . The facility describes the part of the system generating the message. The level is selected from the following .Em ordered (high to low) list: l -tag -width LOG_AUTHPRIV t Dv LOG_EMERG A panic condition. This is normally broadcast to all users. t Dv LOG_ALERT A condition that should be corrected immediately, such as a corrupted system database. t Dv LOG_CRIT Critical conditions, e.g., hard device errors. t Dv LOG_ERR Errors. t Dv LOG_WARNING Warning messages. t Dv LOG_NOTICE Conditions that are not error conditions, but should possibly be handled specially. t Dv LOG_INFO Informational messages. t Dv LOG_DEBUG Messages that contain information normally of use only when debugging a program. .El
p
The
.Fn vsyslog_r
is used the same way as
.Fn vsyslog
except that it takes an additional pointer to a
.Fa syslog_data
structure.
It is a multithread-safe version of the
.Fn vsyslog
function described above.
The
.Fn vsyslog_ss
is the async-signal-safe version of
.Fn vsyslog_r ,
is also multithread-safe, and has the same limitations as
.Fn syslog_ss .
p The .Fn openlog function provides for more specialized processing of the messages sent by .Fn syslog and .Fn vsyslog . The parameter .Fa ident is a string that will be prepended to every message. The .Fa logopt argument is a bit field specifying logging options, which is formed by .Tn OR Ns 'ing one or more of the following values: l -tag -width LOG_AUTHPRIV t Dv LOG_CONS If .Fn syslog cannot pass the message to .Xr syslogd 8 it will attempt to write the message to the console
q Dq Pa /dev/console . t Dv LOG_NDELAY Open the connection to .Xr syslogd 8 immediately. Normally the open is delayed until the first message is logged. Useful for programs that need to manage the order in which file descriptors are allocated. t Dv LOG_NLOG Stops syslog from writing to the system log. Only useful with .Dv LOG_PERROR . t Dv LOG_PERROR Write the message to standard error output as well to the system log. t Dv LOG_PID Log the process id with each message: useful for identifying instantiations of daemons. (This PID is placed within brackets between the ident and the message.) t Dv LOG_PTRIM Trim anything syslog added to the message before writing to standard error output. .El
p The .Fa facility parameter encodes a default facility to be assigned to all messages that do not have an explicit facility encoded: l -tag -width LOG_AUTHPRIV t Dv LOG_AUTH The authorization system: .Xr login 1 , .Xr su 1 , .Xr getty 8 , etc. t Dv LOG_AUTHPRIV The same as .Dv LOG_AUTH , but logged to a file readable only by selected individuals. t Dv LOG_CRON The cron daemon: .Xr cron 8 . t Dv LOG_DAEMON System daemons, such as .Xr routed 8 , that are not provided for explicitly by other facilities. t Dv LOG_FTP The file transfer protocol daemon: .Xr ftpd 8 . t Dv LOG_KERN Messages generated by the kernel. These cannot be generated by any user processes. t Dv LOG_LPR The line printer spooling system: .Xr lpr 1 , .Xr lpc 8 , .Xr lpd 8 , etc. t Dv LOG_MAIL The mail system. t Dv LOG_NEWS The network news system. t Dv LOG_SYSLOG Messages generated internally by .Xr syslogd 8 . t Dv LOG_USER Messages generated by random user processes. This is the default facility identifier if none is specified. t Dv LOG_UUCP The uucp system. t Dv LOG_LOCAL0 Reserved for local use. Similarly for .Dv LOG_LOCAL1 through .Dv LOG_LOCAL7 . .El
p The .Fn openlog_r function is the multithread-safe version of the .Fn openlog function. It takes an additional pointer to a .Fa syslog_data structure. This function must be used in conjunction with the other multithread-safe functions.
p The .Fn closelog function can be used to close the log file.
p The .Fn closelog_r does the same thing as .Xr closelog 3 but in a multithread-safe way and takes an additional pointer to a .Fa syslog_data structure.
p The .Fn setlogmask function sets the log priority mask to .Fa maskpri and returns the previous mask. Calls to .Fn syslog with a priority not set in .Fa maskpri are rejected. The mask for an individual priority .Fa pri is calculated by the macro .Fn LOG_MASK pri ; the mask for all priorities up to and including .Fa toppri is given by the macro .Fn LOG_UPTO toppri . The default allows all priorities to be logged.
p The .Fn setlogmask_r function is the multithread-safe version of .Fn setlogmask . It takes an additional pointer to a .Fa syslog_data structure. .Sh RETURN VALUES The routines .Fn closelog , .Fn closelog_r , .Fn openlog , .Fn openlog_r , .Fn syslog , .Fn syslog_r , .Fn vsyslog , .Fn vsyslog_r , .Fn syslogp , .Fn syslogp_r , .Fn vsyslogp , and .Fn vsyslogp_r return no value.
p The routines .Fn setlogmask and .Fn setlogmask_r always return the previous log mask level. .Sh EXAMPLES d -literal -offset indent -compact syslog(LOG_ALERT, "who: internal error 23"); openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP); setlogmask(LOG_UPTO(LOG_ERR)); syslog(LOG_INFO, "Connection from host %d", CallingHost); syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); syslogp(LOG_INFO|LOG_LOCAL2, NULL, NULL, "foobar error: %m"); syslogp(LOG_INFO, "ID%d