gtpc2m74C/C++ Language Support User's Guide

syslog-Send a Message to the Control Log

This function sends a message to the syslog daemon, which writes the message to an appropriate system log, forwards it to a list of users, or forwards it to the logging facility on another host over the network.

See TPF Transmission Control Protocol/Internet Protocol for more information about the syslog daemon.

Format

#include <syslog.h>
void     syslog(int priority, const char *message, ... /* argument */);

priority
Specify this argument by ORing together a severity level value and, optionally, a facility. If you do not specify a facility value, the current default facility value specified with the openlog function is used.

The severity level value indicates the type of condition this message is associated with and can be one of the following:

LOG_EMERG
An emergency condition; that is, the system cannot be used. This is normally broadcast to all processes.

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

LOG_CRIT
A critical condition, such as hard device error.

LOG_ERR
An error message.

LOG_WARNING
A warning message.

LOG_NOTICE
A condition that is not an error condition, but may require special handling.

LOG_INFO
An informational message.

LOG_DEBUG
A message that contains information normally used only when debugging a program.

The facility indicates the application or system component generating the message, and can be one of the following:

Note:
The TPF system does not have a server for all of these facilities; however, the syslog daemon will accept messages if your environment has such a server.

LOG_AUTH
The message is generated by authorization programs.

LOG_DAEMON
The message is generated by system server processes.

LOG_LOCAL0
Reserved for a user-defined facility.

LOG_LOCAL1
Reserved for a user-defined facility.

LOG_LOCAL2
Reserved for a user-defined facility.

LOG_LOCAL3
Reserved for a user-defined facility.

LOG_LOCAL4
Reserved for a user-defined facility.

LOG_LOCAL5
Reserved for a user-defined facility.

LOG_LOCAL6
Reserved for a user-defined facility.

LOG_LOCAL7
Reserved for a user-defined facility.

LOG_MAIL
The message is generated by a mail system.

LOG_NEWS
The message is generated by a news system.

LOG_SYSLOG
The message is generated by the syslog daemon.

LOG_USER
The message is generated by random processes. This is the default facility identifier if you do not specify a value.

message
A pointer to the message that is to be sent to the logging facility. This message can be followed by additional arguments in the same way as arguments are specified for the printf function. See fprintf, printf, sprintf-Format and Write Data for more information about the format of these arguments.

Notes:

  1. Occurrences of %m in the format string pointed to by the message argument are replaced by the error message string associated with the current value of errno. A trailing new-line character is added if needed.

  2. The total length of the format string and the parameters cannot be greater than 1536 bytes.

Normal Return

Void.

Error Return

Not applicable.

Programming Considerations

Examples

The following example opens a log facility, sends log messages to the syslog daemon, and closes the facility.

#include <syslog.h>
 

·
·
·
/* Open a log facility with the name of local0. Prefix each line in the log file with the program name (tpf) and the process ID. */ openlog("tpf", LOG_PID, LOG_LOCAL0); /* Log an informational message with the specified content */ syslog(LOG_INFO, "Hello from tpf"); /* Close the log facility name. */ closelog();

The following is an example of the line produced in the log file by the previous example:

<May 26 11:27:51>tpf[3014660]: Hello from tpf

Related Information