Controls the system log.
Standard C Library (libc.a)
#include <syslog.h>
int syslog_r (Priority, SysLogData, Format, . . .)
int Priority;
struct syslog_data * SysLogData;
const char * Format;
int openlog_r (ID, LogOption, Facility, SysLogData)
const char * ID;
int LogOption;
int Facility;
struct syslog_data *SysLogData;
void closelog_r (SysLogData)
struct syslog_data *SysLogData;
int setlogmask_r ( MaskPriority, SysLogData)
int MaskPriority;
struct syslog_data *SysLogData;
The syslog_r subroutine writes messages onto the system log maintained by the syslogd daemon.
The messages are similar to the Format parameter in the printf subroutine, except that the %m field is replaced by the current error message obtained from the errno global variable. A trailing new-line character can be added to the message if needed.
Messages are read by the syslogd daemon and written to the system console or log file, or forwarded to the syslogd daemon on the appropriate host.
If a program requires special processing, you can use the openlog_r subroutine to initialize the log file.
The syslog_r subroutine takes as a second parameter a variable of the type struct syslog_data, which should be provided by the caller. When that variable is declared, it should be set to the SYSLOG_DATA_INIT value, which specifies an initialization macro defined in the sys/syslog.h file. Without initialization, the data structure used to support the thread safety is not set up and the syslog_r subroutine does not work properly.
Messages are tagged with codes indicating the type of Priority for each. A Priority is encoded as a Facility, which describes the part of the system generating the message, and as a level, which indicates the severity of the message.
If the syslog_r subroutine cannot pass the message to the syslogd daemon, it writes the message the /dev/console file, provided the LOG_CONS option is set.
The closelog_r subroutine closes the log file.
The setlogmask_r subroutine uses the bit mask in the MaskPriority parameter to set the new log priority mask and returns the previous mask.
The LOG_MASK and LOG_UPTO macros in the sys/syslog.h file are used to create the priority mask. Calls to the syslog_r subroutine with a priority mask that does not allow logging of that particular level of message causes the subroutine to return without logging the message.
Programs using this subroutine must link to the libpthreads.a library.
Item | Description |
---|---|
Priority | Specifies the part of the system generating the message and
indicates the level of severity of the message. The level of severity
is selected from the following list:
|
SysLogData | Specifies a structure that contains the following information:
|
Format | Specifies the format, given in the same format as for the printf subroutine. |
ID | Contains a string attached to the beginning of every message. The Facility parameter encodes a default facility from the previous list to be assigned to messages that do not have an explicit facility encoded. |
LogOption | Specifies a bit field that indicates logging options. The values
of LogOption are:
|
Facility | Specifies which of the following values generated the message:
|
MaskPriority | Enables logging for the levels indicated by the bits in the mask that are set, and disables logging where the bits are not set. The default mask allows all priorities to be logged. |
Item | Description |
---|---|
0 | Indicates that the subroutine was successful. |
-1 | Indicates that the subroutine was not successful. Moves an error code, indicating the specific error, into the errno global variable. |
When the syslog_r subroutine is unsuccessful, the errno global variable can be set to the following values:
Item | Description |
---|---|
EAGAIN | Exceeds the limit on the total number of processes running either system-wide or by a single user, or the system does not have the resources necessary to create another process. |
EBADF | The syslogd daemon is not active. |
ECONNRESET | The syslogd daemon stopped during the operation. |
ENOBUFS | Buffer resources were not available. |
ENOMEM | Not enough space exists for this process. |
ENOTCONN | The syslogd daemon stopped during the operation. |
EPROCLIM | If WLM is running, the limit on the number of processes or threads in the class might have been met. |
EINVAL | The Priority parameter is not a valid parameter. |
syslog_r (LOG_ALERT, syslog_data_struct, "%s", "who:internal error 23");
openlog_r ("ftpd", LOG_PID, LOG_DAEMON, syslog_data_struct);
setlogmask_r (LOG_UPTO (LOG_ERR), syslog_data_struct);
syslog_r (LOG_INFO, syslog_data_struct, "");
syslog_r (LOG_INFO | LOG_LOCAL2, syslog_data_struct, "system error: %m");