---
name: "logsys_overview"
section: "8"
platform: "linux"
package: "corosync"
version: "1.4.6-1.1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/logsys_overview"
---

# logsys\_overview(8)

Logsys Library Overview

## NAME

logsys\_overview - Logsys Library Overview

## OVERVIEW

The logsys library provides a generically usable logging and tracing system for use by applications.  It supports many features including:

Configurable subsystem logging or single system logging

Threaded non-blocking logging of log output data for better non-blocking performance

Support for 8 tracing levels and tracing the entering and leaving of functions

Declaration of logging system or subsystem without calling any functions

Dynamic reconfiguration of the logging system parameters

Logging to syslog, file, stderr.

## Declaration of the System logger

The logsys library is initially configured by including logsys.h and declaring a logger.  Once the logger is declared, optional subsystem loggers can be declared in every file.

The definition LOGSYS\_DECLARE\_SYSTEM is placed after the include section of one C file in the application.  This declaration creates a constructor function which will be called automatically before main() is executed.  This technique avoids the need for calling any setup functions in short applications that don't require it and enables full logging capabilities before any application code is executed.

\#define LOGSYS\_DECLARE\_SYSTEM (name, mode, debug, file, file\_priority, syslog\_facility, syslog\_priority, format, fltsize)

The name parameter is the name of the application or system.

The mode parameter is the logging mode of the system. The following modes can be configured by logically ORing these flags:

LOGSYS\_MODE\_OUTPUT\_FILE: Output all log data to the file parameter of this declaration

LOGSYS\_MODE\_OUTPUT\_STDERR: Output all log data to the stderr descriptor

LOGSYS\_MODE\_OUTPUT\_SYSLOG: Output all log data to syslog using a non-blocking thread

LOGSYS\_MODE\_FORK: This flags tells logsys to queue all data untill the application has forked. The application is then responsible to call logsys\_fork\_completed to flush the queue and start logging.

LOGSYS\_MODE\_THREADED: Starts a separate thread to handle non-blocking logging operations. If this flag is not specified, the logging operations are blocking.

The debug parameter, if enabled, turns off all messages priority filtering, recording everything everywhere.

The file parameter specifies the filename that should be used to log messages. This parameter may be NULL and no log file will be created.

The file\_priority parameter specifies the message priority that should be logged to file.

The syslog\_facility parameter is the syslog facility that should be used when logging messages.

The syslog\_priority, similar to file\_priority, specifies the message priority that should be logged to syslog.

The format parameter allows to set custom output format. Set to NULL to use built-in default.

The fltsize parameter specifies the flight recorder buffer size in bytes. The requested value is increased by the size of 2 unsigned ints and rounded to the next PAGE\_SIZE.

An example declaration would be:

\#include \<corosync/logsys.h\>

LOGSYS\_DECLARE\_SYSTEM ("test",                            /\* name \*/\
         LOGSYS\_MODE\_OUTPUT\_STDERR \| LOGSYS\_MODE\_THREADED, /\* mode \*/\
         0,                                                /\* debug \*/\
         NULL,                                             /\* logfile path \*/\
         LOGSYS\_LEVEL\_INFO,                                /\* logfile\_priority \*/\
         LOG\_DAEMON,                                       /\* syslog facility \*/\
         LOGSYS\_LEVEL\_INFO,                                /\* syslog level \*/\
         NULL,                                             /\* use default format \*/\
         1000000\);                                         /\* flight recorder size \*/

## Declaration of subsystems

The logsys library supports the logging of information to one main system or subsystem.  This is specified in each individual object C file in the system and it is entirely optional.

An example:

LOGSYS\_DECLARE\_SUBSYS ("subsystest");

It is possible to use the same subsystem name in separate object files. In this case, the individual logging parameters for those subsystem identifier will be used.

A newly created subsystem inherits the system configuration at the time of creation.

It is possible to override every configuration option on a subsystem base throught the configuration API.

## Logging Messages

The definition log\_printf is used to log information to the log.  It works in a similiar fashion to printf, except it has a first parameter of level which may be the following: LOGSYS\_LEVEL\_EMERG LOGSYS\_LEVEL\_ALERT LOGSYS\_LEVEL\_CRIT LOGSYS\_LEVEL\_ERR LOGSYS\_LEVEL\_WARNING LOGSYS\_LEVEL\_NOTICE LOGSYS\_LEVEL\_INFO LOGSYS\_LEVEL\_DEBUG

An example of using log\_printf would be

log\_printf (LOGSYS\_LEVEL\_EMERG, "This is an emergency %s value %d0, string, value);

Tracing of functions can be done using ENTER(), LEAVE();

An example of using ENTER is void function (char \*name) { ENTER(); LEAVE(); }

Individual tracing levels are supported through the macros TRACE1(format, args) TRACE2(format, args) TRACE8(format, args)

An example of using TRACE is

char \*name = "test"; TRACE7 ("This is a trace 7 log with name %s0, name);

Note that ENTER/LEAVE/TRACE\* calls are recorded only in the flight recorder.

## SEE ALSO

**logsys\_fork\_completed**(3), **logsys\_atexit**(3), **logsys\_log\_rec\_store**(3), **logsys\_format\_set**(3), **logsys\_format\_get**(3), **logsys\_config\_mode\_set**(3), **logsys\_config\_file\_set**(3), **logsys\_config\_syslog\_facility\_set**(3), **logsys\_config\_syslog\_facility\_get**(3), **logsys\_config\_mode\_set**(3), **logsys\_config\_mode\_get**(3), **logsys\_config\_file\_set**(3), **logsys\_config\_logfile\_priority\_set**(3), **logsys\_config\_debug\_set**(3), **logsys\_facility\_id\_get**(3), **logsys\_facility\_name\_get**(3), **logsys\_priority\_id\_get**(3), **logsys\_priority\_name\_get**(3),
