lobot::Metrics::Log Class Reference

A class for creating metrics related log messages and buffering them with the metrics behaviour for subsequent output to the log file. More...

#include <Robots/LoBot/control/LoMetrics.H>

Collaboration diagram for lobot::Metrics::Log:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Log ()
 ~Log ()
template<typename T >
Logoperator<< (const T &)
 operator std::ostringstream & ()

Friends

Logoperator<< (Log &, const endl &)
Logoperator<< (Log &, const newl &)

Detailed Description

A class for creating metrics related log messages and buffering them with the metrics behaviour for subsequent output to the log file.

To create metrics related log messages, client behaviours should create a local instance of the Metrics::Log class and use the stream insertion operator to write messages to the metrics log file. The constructor of this class takes care of time-stamping each message and the destructor buffers the message with the Metrics behaviour. Here is the intended usage pattern for this class:

void some_class::some_function() { Pose p = something_complicated() ; Metrics::Log() << "current pose: " << p.x() << ' ' << p.y() << ' ' << p.t() ; }

When the local Log object created in the chained operator<< statement goes out of scope, the message will be added to the Metrics behaviour's internal message buffer, which will then take care of periodically dumping all the messages to the log file.

NOTE: It is not shown in the above example; however, clients may use I/O manipulators to get formatted output. But please don't end with newlines; those are added automatically when the message buffer is dumped to the log file.

NOTE 2: To break up long lines, use the Metrics::newl "manipulator" like so:

void some_class::some_function() { Metrics::Log() << "a fantastically long message that needs" << Metrics::newl() << "to be broken up across multiple lines" ; }

The Metrics::newl manipulator will introduce a space followed by a backslash followed by a newline and then indent the next line in the log with eight spaces to indicate that this line is a continuation of the previous one.

NOTE 3: Although the above examples illustrate using the metrics logging facility with an unnamed temporary object, it is also perfectly acceptable to explicitly create a Metrics::Log object and use it multiple times. However, keep in mind that all log messages will be treated as a single log entry and will show up on one line unless you use the Metrics::endl manipulator as shown below:

void some_class::some_function() { Metrics::Log metlog ; metlog << "this is the first entry" << Metrics::endl() ; metlog << "this is the second entry" << Metrics::endl() ; metlog << "oops, this and the next line" ; metlog << "are both part of the same log entry!" ; }

Definition at line 224 of file LoMetrics.H.


Constructor & Destructor Documentation

lobot::Metrics::Log::Log (  ) 

When a Metrics::Log object is created, it will automatically cause a time-stamp to be prefixed to the message.

Definition at line 235 of file LoMetrics.C.

lobot::Metrics::Log::~Log (  ) 

When a Metrics::Log object goes out of scope, it will queue the message with the metrics behaviour, which, in turn, will take care of periodically writing the messages to the log file.

Definition at line 242 of file LoMetrics.C.


Member Function Documentation

lobot::Metrics::Log::operator std::ostringstream & (  )  [inline]

Conversion operator. This function converts Metrics::Log objects to std::ostringstream objects. This allows clients to simply reuse their operator<< definitions for std::ostream and not have to provide an overload for use with Metrics::Log.

Definition at line 274 of file LoMetrics.H.

template<typename T >
Metrics::Log & lobot::Metrics::Log::operator<< ( const T &  t  )  [inline]

The stream insertion operator for arbitrary data types.

To create log entries, clients should instantiate the Metrics::Log class and "build" the full message by chaining multiple calls to this operator. When the Metrics::Log object goes out of scope, the message will be queued with the metrics behaviour.

Definition at line 303 of file LoMetrics.H.


Friends And Related Function Documentation

Log& operator<< ( Log ,
const newl  
) [friend]

This function breaks up long log entries into multiple lines by inserting a newline and indenting the next line of a multiple line log entry with two tabs.

Log& operator<< ( Log ,
const endl  
) [friend]

This function ends a log entry and begins a new one. It is meant for use with Metrics::Log objects created explicitly so that they may be "reused" to output multiple log messages.


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:44:28 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3