slogf()

Send a message to the system logger

Synopsis:

#include <stdio.h>
#include <sys/slog.h>

int slogf( int opcode,
           int severity, 
           const char * fmt,
           ... );

Arguments:

opcode
A combination of a major and minor code. Create the opcode using the _SLOG_SETCODE(major, minor) macro that's defined in <sys/slog.h>.

The major and minor codes are defined in <sys/slogcodes.h>.

severity
The severity of the log message; see Severity levels,” below.
fmt
A standard printf() string followed by printf() arguments.

The formatting characters that you use in the message determine any additional arguments.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Note: This function is in libc.a, but not in libc.so (in order to save space).

Description:

The slog*() functions send log messages to the system logger, slogger2. To send formatted messages, use slogf(). If you have programs that scan log files for specified codes, you can use slogb() or slogi() to send a block of structures or ints, respectively.

The vslogf() function is an alternate form in which the arguments have already been captured using the variable-length argument facilities of <stdarg.h>.

Severity levels

There are eight levels of severity defined. The lowest severity is 7 and the highest is 0. The default is 7.

Manifest Name Severity value Description
_SLOG_SHUTDOWN 0 Shut down the system NOW (e.g., for OEM use)
_SLOG_CRITICAL 1 Unexpected unrecoverable error (e.g., hard disk error)
_SLOG_ERROR 2 Unexpected recoverable error (e.g., needed to reset a hardware controller)
_SLOG_WARNING 3 Expected error (e.g., parity error on a serial port)
_SLOG_NOTICE 4 Warnings (e.g., out of paper)
_SLOG_INFO 5 Information (e.g., printing page 3)
_SLOG_DEBUG1 6 Debug messages (normal detail)
_SLOG_DEBUG2 7 Debug messages (fine detail)

If you want the data in the log message to be interpreted as text, use a bitwise OR to add _SLOG_TEXTBIT to the severity. If this bit is set, slogf() and vslogf() also write the log message on stderr.

Returns:

The size of the message sent to slogger2, or -1 if an error occurs.

Errors:

Any value from the Errors section in MsgSend(), as well as:

EACCES
Insufficient permission to write to the log file.
ENOENT
Invalid log file or directory specified, or slogger2 isn't running.

Examples:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/slog.h>
#include <sys/slogcodes.h>

int main() {
  int i;

  for(i = 0 ; ; i++) {
    switch(rand() % 3) {
    case 0:
      slogb( _SLOG_SETCODE(_SLOGC_TEST, 0),
             _SLOG_DEBUG1, &i, sizeof(i));
      break;

    case 1:
      slogi( _SLOG_SETCODE(_SLOGC_TEST, 1),
             _SLOG_CRITICAL, 1, i);
      break;

    case 2:
      slogf( _SLOG_SETCODE(_SLOGC_TEST, 2),
              _SLOG_ERROR, 
             "This is number %d", i);
      break;
    }

    sleep(1);
  }
}

Classification:

QNX Neutrino

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes