(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Logging Streams

Description:

Keywords: ecl streams

Tutorial Level: INTERMEDIATE

Contents

  1. Overview
  2. Usage

Overview

LogStream is a convenient, fast means to logging from multiple threads with multiple customisable modes. They can also optionally automatically insert header and timestamp information.

The LogStream class is now mostly irrelevant if you are using ros logging, though they are sometimes a useful low overhead alternative (don't need the sometimes difficult to compile apache libraries) for logging, specially when cross compiling.

Usage

Multiple modes are most conveniently utilised via customised enums. For example:

   1 enum LogModes {
   2     Warning,
   3     Error,
   4     Debug,
   5 };  

Note that this is an advantage over alot of other loggers in that it gives you the freedom to define your own error logging levels. Each mode can then be associated inside the log stream with its own customised header.

   1 LogStream log_stream("test.log")
   2 log_stream.enableMode(Warning,"WARNING");
   3 log_stream.enableMode(Error,"ERROR");
   4 log_stream.enableMode(Debug,"DEBUG");

This process can be repeated from multiple threads each with its own instance of the log stream attached to the single file. Using the log stream is then done via the macros LOG and FLUSH

   1 LOG(log_stream, Warning) << "This is a log message from main().\n";
   2 FLUSH(log_stream)

By default this will automatically add header and timestamp information. You can manually disable these if you prefer.

Wiki: ecl_streams/Tutorials/Logging Streams (last edited 2012-01-30 00:39:36 by DanielStonier)