SignalLogger
A library for signal logging.
Use the signal logger in your program

Access the logger

The signal logger is stored as a global shared pointer and can be accessed from everywhere in the current process.

// Including the logger
// Accessing the logger

Set the logger type

In the source file of your main application add:

// Include signal logger

Then when initializing the application set the desired logger type. Three types of loggers are provided:

  • SignalLoggerNone is an empty implementation of the logger
    // Resetting the logger to type none
  • SignalLoggerStd provides the functionality to write a binary log file
    // Resetting the logger to type std
  • SignalLoggerRos extends the SignalLoggerStd with a ros publishing functionality
    /* Resetting the logger to type ros
    * -> Needs a pointer to a nodehandle (e.g. to advertise publishers)
    */

To initialize the logger you have to call signal_logger::SignalLoggerBase::initLogger() with options of type signal_logger::SignalLoggerOptions.

The maximal logging time is necessary s.t. the logger can allocate sufficient memory for the time log element. If 'maxLogTime' is zero a growing time buffer is initialized, else a fixed size time buffer of size (collectFrequency*maxLogTime) is allocated. If all elements are stored in buffers of looping type the time element is stored in a looping buffer.

signal_logger::logger->initLogger(options);

Add variables to the logger

To add a variable to the logger use the signal_logger::add() function. This function is templated and most types are supported. A subset of the supported types is given in LogElementTypes.hpp. Variables can also be added in helper libraries of your main application.

signal_logger::add(myVar, name, group, unit, divider, action, bufferSize, bufferType);
  • myVar: The variable you want to log. The ptr to this variable has to be constant and valid until the end of the program.
  • name: The name of the log variable.
  • group: The namespace of the logger variable. Allows grouping of log variables.
  • unit: The physical unit of the logged variable.
  • divider: The default divider of the log variable. (divider = 'collect frequency' / 'log var frequency') )
  • action: The action that shall be performed for the log element. (see signal_logger::LogElementAction)
  • bufferSize: The size of the buffer.
  • bufferType: The type of the buffer. (see signal_logger::BufferType)

However, this will have no effect until the update function signal_logger::SignalLoggerBase::updateLogger() is called. Try to call this function at the end of the configuration, since this function will open a file stream and parse (a potentially big) yaml file. If you are using the signal_logger in combination with rocoma it is worthwhile to know that updateLogger() is called after the initialization of every "normal" controller.

signal_logger::logger->updateLogger();

Collect logger data

The activated/enabled elements of the logger are collected when signal_logger::SignalLoggerBase::collectLoggerData() is called and the logger was started. It is required that this function is called with the 'collectFrequency' specified in the init function. If you are using the signal_logger in combination with rocoma collectLoggerData is called after the advancing of every "normal" or "emergency" controller.

signal_logger::logger->collectLoggerData();

Start/Stop the logger

To start and stop the logger following functions are provided. When starting the logger the buffers are cleared. If you are using the signal_logger in combination with rocoma the logger is started on initialization and stopped in the pre-stop of every "normal" or "emergency" controller.

signal_logger::logger->startLogger();
signal_logger::logger->stopLogger();
signal_logger::logger->restartLogger();

Save the logger data

The standard logger implements saving the data to a binary, bag or csv file. The type of files can be selected by passing a vector of signal_logger::LogFileType. The saving is done in a different, detached thread. As a first step the complete buffer data is copied and flushed. Then the logger can continue to collect data, while the copies are saved into a binary/bag file.

signal_logger::logger->saveLoggerData( {LogFileType::BINARY, LogFileType::CSV} );
signal_logger::logger->stopAndSaveLoggerData();

Publish the logger data

The ros logger implements publishing data over ros. The signal_logger::SignalLoggerBase::publishData() function can be executed in parallel to the collect function. To prevent data loss, make sure the publishing thread runs at a sufficient frequency.

signal_logger::logger->publishData();

Cleanup the logger

You should shutdown the signal logger in the destructor of your main application. E.g the signal logger ros should shutdown all ros communication as long as the nodehandle is still valid.

Save logger script

To generate a logger script you can call this function when the logger is setup properly. It will store the current logger configuration into a file located at the default location(signal_logger::LOGGER_DEFAULT_SCRIPT_FILENAME).

signal_logger::logger->saveLoggerScript();