Logging

To create log messages the RTC Toolkit makes use of the well-established log4cplus logging library which will also be used by the CII Logging service.

For each RTC Component two default loggers with consistent configuration are created, the names of these logger are rtctk and app. While the rtctk logger is used by RTC Tk provided code, instrument RTC developers shall use the app logger for their extensions and custom developments. This allows to easily identify whether certain logs messages stem from RTC Tk or from concrete RTC code. Instrument RTC developers are also free to introduce additional loggers below app like app.foobar to introduce a hierarcy.

Note

To ensure a consistent and uniform log message format across all instruments it is strongly recommended to make use of the toolkit-provided logging infrastructure rather than defining custom log.properties configuration files. This will greatly simplify collection and parsing of log files by other tools.

All SRTC components that use RtcComponentMain do, nevertheless, accept a custom log.properties file through the -l | --lpf command line option. This is made available for certain debugging purposes only. The following is an example of starting a component with a custom configuration:

$ rtctkExampleDataTaskTelemetry data_task_1 -l mylog.properties

Refer to the log4cplus documentation about the format of the log.properties files.

API Usage

In RTC Component code, the following header file must be included to enable the use of the logging API:

#include <rtctk/componentFramework/logger.hpp>

Log messages can be created using the default LOG4CPLUS logging macros and the toolkit-provided method GetLogger() which retrieves the default logger when called without any argument.

#include <rtctk/componentFramework/logger.hpp>

using rtctk::componentFramework::GetLogger;

LOG4CPLUS_INFO(GetLogger(), "My log message.");
LOG4CPLUS_INFO(GetLogger("app"), "My log message."); // equivalent to line before
LOG4CPLUS_INFO(GetLogger("app.foobar"), "My log message."); // introduces custom child logger

Log Files

Generated log messages can either be viewed on the console or in the generated log files:

  • By default, a combined logfile can be found in /var/log/elt/elt.log and viewed with the ciiLogViewer application.

  • For development purposes, RTC Toolkit creates additional log files (one for each RTC Component instance) in the directory specified by environment variable $RTC_LOGS or $INTROOT/logsink/, if either of $RTC_LOGS or $INTROOT is defined. $RTC_LOGS takes precedence however.

The exact format for log messages depends on the log output location, but it always includes time-stamp, severity, logger-name and log message. Here is an example from console logging:

[17:22:30:158][INFO , app] My log message.

Note

There are multiple ways to change the log-level: At component startup it can be set to DEBUG by adding the -d commandline flag, later it can be overwritten using API function GetLogger().setLogLevel(). During runtime it can be adjusted by sending command SetLogLevel from client applications like rtctkClient.