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 a default logger with a consistent configuration is created, the name of this logger corresponds to the component instance name. Developers are free to make use of this default logger or to create additional loggers using the toolkit-provided API methods.

Note

To ensure a consistent and uniform log message format across all the 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 -s service_disc.yaml -l mylog.properties

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

API Usage

The following header file must be included to be able to use 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 component’s default logger when called without argument.

#include <rtctk/componentFramework/logger.hpp>


using rtctk::componentFramework::GetLogger;

LOG4CPLUS_INFO(GetLogger(), "My log message.");

Custom Loggers need to be created explicitly using the MakeLogger() method, after creation they can be used by retrieving the respective logger instance by name:

#include <rtctk/componentFramework/logger.hpp>


using rtctk::componentFramework::MakeLogger;
MakeLogger("my_logger", log4cplus::INFO_LOG_LEVEL);

using rtctk::componentFramework::GetLogger;
LOG4CPLUS_INFO(GetLogger("my_logger"), "My log message.");

Generated log messages can either be viewed on the console or in the generated log files. By default a log file will be created for each RTC Component instance in directory specified by environment variable $RTC_LOGS or $INTROOT/logsink/ if $RTC_LOGS is not defined.

The standard format for log messages is toolkit-defined and currently includes time-stamp, severity, logger-name and log message. Here is an example:

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

Note

There are multiple ways to change the log-level: During component startup it can be defined during logger creation with MakeLogger(), later it can be overwritten using API function GetLogger().setLogLevel(). During runtime it can be adjusted by sending command SetLogLevel with the rtctkClient application.