ePrivacy and GPDR Cookie Consent by Cookie Consent

Logging

hermes is used for creating diagnostic messages at runtime. Amongst other things it is useful for debugging purposes and to diagnose errors in shipped software.

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.

hermes 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 hermes 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 process to continue working. The program state is valid though and thus the program can continue running.

2

LL_ERROR

An error occurred.

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

5

LL_DEBUG

Information for the user about the proces.

6

LL_TRACE

Information about internal processes.

7

LL_SPAM

Detailed information about internal processes.

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. This is useful if you don't want any logging overhead in your code, but you don't want to remove your logging code either. Also you could activate logging for debug builds and deactivate it for release builds like this.