ePrivacy and GPDR Cookie Consent by Cookie Consent

Logging

The logger is used for recording data inside the state machine at runtime. It is useful for debugging purposes and to get an insight into the running the state machine.

Starting the log

Logging is enabled by getting a reference to the log manager (a singleton), setting a log level for the messages and by adding a logger (file logger, console logger, custom logger).

Now simply start the log manager and it will launch a new thread. The logging thread logs to the specified locations including: the console, to file, syslog, etc...

Call run() to begin.

Stopping the log

When the logger is done being used, call the halt() method. This is not enough to stop the logger though. After halt(), the user has to call join() on the logger to finally join the logging thread.

From version 0.7.0, yasmine provides the convenience method halt_and_join() for stopping and joining the logger in a single step.

The two step stopping procedure is useful if you have other threads that need to be stopped. Thus you can first trigger to stop all threads and then join them. This will reduce shut down time.

Custom loggers

You can write custom loggers to log to new target locations (syslog, Windows event log, ...) or to forward the yasmine log messages to your own logging system. To do this implement the logger interface.

Macros

There are two macros available for using the logger: SX_LOG and SX_LOG_HEX.

SX_LOG is for text messages with placeholder replacement. It generates one line in the log.

SX_LOG_HEX is a logging macro that can log hex editor style. It's useful to display binary data.

Example

An example is available on the hello_yasmine project page.

Log levels

Index

Name

Description

-1

LL_OFF

Used to turn logging off. This value is set as default when the log manager is created.

0

LL_ASSERT

Error in internal logic that we cannot recover from. In DEBUG mode assert is called next, In RELEASE mode a program crash can be expected next.

1

LL_FATAL

Internal error which makes it impossible for the state machine to continue working. The program state is valid though and thus the program can continue running.

2

LL_ERROR

An error occurred (e.g. defect in defined state machine, event cannot be fired because state machine is not running).

3

LL_WARN

An unusual condition occurred that could be an error (e.g. a timed event could not be cancelled, this could be a logic error or the event might have just fired).

4

LL_INFO

Important information for the user about the state machine.

5

LL_DEBUG

Information for the user about the state machine.

6

LL_TRACE

Information about internal processes in the state machine. Usually only useful for developers of yasmine.

7

LL_SPAM

Detailed information about internal processes in the state machine. Usually only useful for developers of yasmine.

A smaller index implies a higher priority.

Disabling logging

In order to completely disable logging, compile the library with SX_NO_LOGGING defined. Then the log macros expands to nothing and thus no code is generated and no run-time overhead occurs.