Send a message to the system logger


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

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


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>.

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

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



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 (in order to save space).


The slog*() functions send log messages to the system logger, slogger. 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>.

(QNX Neutrino 6.6) You can't redirect slogger output to slogger2 in general, but if a program uses the slogger APIs, you can preload the library when you start the program, in order to redirect its logs: my_program

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.


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


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

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


#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));

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

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



QNX Neutrino

Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes