dynamicgraph::RealTimeLogger Class Reference

Main class of the real-time logger. More...

#include <dynamic-graph/real-time-logger.h>

Public Member Functions

 RealTimeLogger (const std::size_t &bufferSize)
 
void clearOutputStreams ()
 
void addOutputStream (const LoggerStreamPtr_t &os)
 
bool spinOnce ()
 Write next message to output. More...
 
RTLoggerStream front ()
 Return an object onto which a real-time thread can write. More...
 
void frontReady ()
 
bool empty () const
 
bool full () const
 
std::size_t size () const
 
std::size_t getBufferSize ()
 
 ~RealTimeLogger ()
 

Static Public Member Functions

static RealTimeLoggerinstance ()
 
static void destroy ()
 

Detailed Description

Main class of the real-time logger.

It is intended to be used like this:

#define ENABLE_RT_LOG
// Somewhere in the main function of your executable
int main (int argc, char** argv) {
}
// Somewhere in your library
dgRTLOG() << "your message. Prefer to use \n than std::endl."
Note
Thread safety. This class expects to have:
  • only one reader: the one who take the log entries and write them somewhere.
  • one writer at a time. Writing to the logs is never a blocking operation. If the resource is busy, the log entry is discarded.

Constructor & Destructor Documentation

dynamicgraph::RealTimeLogger::RealTimeLogger ( const std::size_t &  bufferSize)
Todo:
add an argument to preallocate the internal string to a given size.
dynamicgraph::RealTimeLogger::~RealTimeLogger ( )

Member Function Documentation

void dynamicgraph::RealTimeLogger::addOutputStream ( const LoggerStreamPtr_t os)
inline
void dynamicgraph::RealTimeLogger::clearOutputStreams ( )
inline
static void dynamicgraph::RealTimeLogger::destroy ( )
static
bool dynamicgraph::RealTimeLogger::empty ( ) const
inline
RTLoggerStream dynamicgraph::RealTimeLogger::front ( )

Return an object onto which a real-time thread can write.

The message is considered finished when the object is destroyed.

void dynamicgraph::RealTimeLogger::frontReady ( )
inline
bool dynamicgraph::RealTimeLogger::full ( ) const
inline
std::size_t dynamicgraph::RealTimeLogger::getBufferSize ( )
inline
static RealTimeLogger& dynamicgraph::RealTimeLogger::instance ( )
static
std::size_t dynamicgraph::RealTimeLogger::size ( ) const
inline
bool dynamicgraph::RealTimeLogger::spinOnce ( )

Write next message to output.

It does nothing if the buffer is empty.

Returns
true if it wrote something