MLIB
Loading...
Searching...
No Matches
Syslog Emulator

Emulation of Unix syslog functionality. More...

Functions

void openlog (const char *ident, int option, int facility)
 Open connection to logger.
 
void closelog ()
 closelog also resets the identification string for syslog messages back to the default, if openlog was called with a non-NULL argument to ident.
 
void syslog (int facility_priority, const char *fmt,...)
 Generate a log message using FMT string and option arguments.
 
int setlogmask (int mask)
 The setlogmask() function sets this logmask for the current process, and returns the previous mask.
 
int setlogopt (int opt)
 Set option flags.
 

Detailed Description

Emulation of Unix syslog functionality.

For the most part the functions are compatible with standard BSD syslog functions. The only significant addition is the set_log_ini_param function that allows control of syslog options from an INI file.

Function Documentation

◆ closelog()

void closelog ( void  )

closelog also resets the identification string for syslog messages back to the default, if openlog was called with a non-NULL argument to ident.

Close connection to logger.

The default identification string is the program name.

◆ openlog()

void openlog ( const char *  ident,
int  option,
int  facility 
)

Open connection to logger.

Parameters
identstring prepended to every message, typically set to the program name.
optionflags which control the operation of subsequent calls to syslog().
facilityestablishes a default to be used if none is specified in subsequent calls to syslog()

The use of openlog is optional; it will automatically be called by syslog() if necessary, in which case ident will default to NULL.

If ident is NULL, or if openlog is not called, the default identification string used in syslog messages will be the program name.

You can cause the syslog to drop the reference to ident and go back to the default string (the program name), by calling closelog().

◆ setlogmask()

int setlogmask ( int  mask)

The setlogmask() function sets this logmask for the current process, and returns the previous mask.

Set the log mask level.

If the mask argument is 0, the current logmask is not modified.

A process has a log priority mask that determines which calls to syslog may be logged. All other calls will be ignored. Logging is enabled for the priorities that have the corresponding bit set in mask.

setlogmask sets a mask (the "logmask") that determines which future syslog calls shall be ignored. You can use setlogmask to specify that messages of particular priorities shall be ignored in the future.

If a program has not called setlogmask, the default mask loaded from the INI file (through set_log_ini_param() function) is used. If there is no mask specified in INI file the default is to process everything except LOG_DEBUG.

A setlogmask call overrides any previous setlogmask call.

Note that the logmask exists entirely independently of opening and closing of Syslog connections.

mask is a bit string with one bit corresponding to each of the possible message priorities. If the bit is on, syslog handles messages of that priority normally. If it is off, syslog discards messages of that priority.

Use the message priority values described in <log.h> and the LOG_MASK or LOG_UPTO macros to construct an appropriate mask value, as in this example:

LOG_MASK(LOG_EMERG) | LOG_MASK(LOG_ERROR)

or

~(LOG_MASK(LOG_INFO))

The LOG_UPTO macro generates a mask with the bits on for a certain priority and all priorities above it:

LOG_UPTO(LOG_ERROR)

The unfortunate naming of the macro is due to the fact that internally, higher numbers are used for lower message priorities.

◆ setlogopt()

int setlogopt ( int  opt)

Set option flags.

Parameters
optcan be any combination of LOGOPT_... values.

For instance

    setlogoption (LOGOPT_FILE | LOGOPT_NOUDP)

turns on file logging and turns off sending of UDP data.

The new options take effect immediately.

◆ syslog()

void syslog ( int  facility_priority,
const char *  fmt,
  ... 
)

Generate a log message using FMT string and option arguments.

Parameters
facility_prioritycombined facility and priority value. See below.
fmtprintf-like format string
...any other arguments required by format

If the corresponding priority bit in log mask is set, (see setlogmask()) syslog submits the message with the facility and priority for processing.

The message is prepended with an identification string set in openlog() or by the program name if openlog hasn't been called.

The macro LOG_MAKEPRI generates a facility/priority from a facility and a priority, as in the following example:

    LOG_MAKEPRI(LOG_USER, LOG_WARNING)

Example:

       syslog (LOG_MAKEPRI(LOG_USER, LOG_ERROR),
          "Unable to make network connection to %s.", host );