Logger Class Reference

#include <rtt/Logger.hpp>

List of all members.


Detailed Description

A simple logging class to debug/ analyse what is going on in the Orocos system.

You MUST NOT use this logger in a HARD realtime task or thread.

You can disable all logging at compile time by defining OROBLD_DISABLE_LOGGING (not advised for normal usage). This class can log to a console, and/or to a file and/or to an internal buffer which may be emptied by another class. This is decided upon compile time and can not be changed during runtime. Both printf/iostream are supported.

Example Usage :

     Logger::log() << Logger::Error << "An error Occured !" << Logger::endl;
     Logger::log() << Logger::Debug << "All debug info ..." << Logger::endl;
     * 

When the application is started, set the displayed loglevel with setLogLevel() with a LogLevel parameter. The default is Warning. Set the desired log streams ( a file or std output ) with logToStream() and setStdStream(). Additionally, an orocos.log which is always logs at log level 'Info'.

If you set an environment variable ORO_LOGLEVEL=0..6, this value will be used to determine the output level until overriden by the application (if so). The ORO_LOGLEVEL has the same effect on the 'orocos.log' file, but can not lower it below "Info".

Warning:
Use Logger::RealTime to log from real-time threads. As long as the output LogLevel is 6 or lower, these messages will not appear and do no harm to real-time performance. You need to call
Logger::log().allowRealTime(); 
once in your program to confirm this choice. AGAIN: THIS WILL BREAK REAL-TIME PERFORMANCE.

Definition at line 88 of file Logger.hpp.


Public Types

enum  LogLevel {
  Never = 0, Fatal, Critical, Error,
  Warning, Info, Debug, RealTime
}
 Enumerate all log-levels from absolute silence to everything. More...
typedef std::ostream &(* LogFunction )(std::ostream &)
 Function signature of the functions that influence the log stream.

Public Member Functions

void allowRealTime ()
 Allow messages of the LogLevel 'RealTime' to appear on the console.
void disallowRealTime ()
 Disallow messages of the LogLevel 'RealTime' to appear on the console.
Loggerin (const char *modname)
 Inform the Logger of the entry of a module.
Loggerout ()
 The counterpart of in().
const char * getLogModule () const
 Get the name of the current Log generating Module.
void startup ()
 Print a 'welcome' string in Info and reset log timestamp.
void shutdown ()
 Print a 'goodbye' string in Info, Flush all streams and stop Logging.
std::string getLogLine ()
 This method gets all messages upto level Info and can be freely read by the user, removing the line from an internal buffer of Logger.
void setStdStream (std::ostream &stdos)
 Set the standard output stream.
template<class T>
Loggeroperator<< (T t)
 Send (user defined) data into this logger.
Loggeroperator<< (LogLevel ll)
 Set the loglevel of the incomming messages.
Loggeroperator<< (const std::string &)
 Log a string.
Loggeroperator<< (const char *)
 Log a text message.
Loggeroperator<< (std::ostream &(*pf)(std::ostream &))
 Catch the std::endl and other stream manipulators.
void setLogLevel (LogLevel ll)
 Set the loglevel of the outgoing (streamed) messages.
LogLevel getLogLevel () const
 Return the current output loglevel.
void logflush ()
 Flush log buffers.
void logendl ()
 Add endl and flush buffers.
void lognl ()
 Add newline without flushing buffers.

Static Public Member Functions

static std::ostream & nl (std::ostream &__os)
 Insert a newline '
' in the ostream.
static std::ostream & endl (std::ostream &__os)
static std::ostream & flush (std::ostream &__os)
 Flush the output stream.
static LoggerInstance ()
 Get the singleton logger.
static void Release ()
 Delete the singleton logger.
static Loggerlog ()
 As Instance(), but more userfriendly.
static Loggerlog (LogLevel ll)
 As log(), but also specify the LogLevel of the next message.

Classes

struct  D
 This hidden struct stores all data structures required for logging. More...
struct  In
 Notify the Logger in which 'module' the message occured. More...

Member Enumeration Documentation

enum LogLevel

Enumerate all log-levels from absolute silence to everything.

Warning:
If you enable 'RealTime' logging, this may break realtime performance. Use With Care and NOT on production systems.
See also:
allowRealTime()
Enumerator:
Never 
Fatal 
Critical 
Error 
Warning 
Info 
Debug 
RealTime 

Definition at line 100 of file Logger.hpp.


Member Function Documentation

Logger & in ( const char *  modname  ) 

Inform the Logger of the entry of a module.

See also:
In. Use Logger::In(modname) for management.

Definition at line 357 of file Logger.cpp.

References Logger::D::moduleptr.

Referenced by Logger::In::In().

Logger & out (  ) 

The counterpart of in().

See also:
In. Use Logger::In(modname) for management.

Definition at line 363 of file Logger.cpp.

References Logger::D::loggermodule, and Logger::D::moduleptr.

Referenced by Logger::In::~In().

std::ostream & nl ( std::ostream &  __os  )  [static]

Insert a newline '
' in the ostream.

(Why is this not in the standard ?)

Definition at line 316 of file Logger.cpp.

Referenced by ActionProxy::ActionProxy(), CommandProxy::CommandProxy(), ControlTaskProxy::ControlTaskProxy(), ConnectionFactory::createDataObject(), ControlTaskProxy::DestroyOrb(), StatementProcessor::D::doPrint(), EventC::emit(), StatementProcessor::execute(), MethodC::execute(), CommandC::execute(), ExpressionProxy::ExpressionProxy(), SimulationThread::initialize(), ControlTaskProxy::InitOrb(), Logger::lognl(), Logger::operator<<(), RTT::OS::periodicThread(), Logger::startup(), and PeriodicThread::stop().

void setStdStream ( std::ostream &  stdos  ) 

Set the standard output stream.

(default is cerr).

Definition at line 454 of file Logger.cpp.

References Logger::D::stdoutput.

Logger & operator<< ( t  )  [inline]

Send (user defined) data into this logger.

All data with lower priority than the current loglevel will be discarded. If any loglevel (thus in or out) is set to Never, it will never be displayed. You must flush() or end with std::endl to get the log's output in your file or display.

Definition at line 16 of file Logger.inl.

Referenced by Logger::operator<<().

Logger & operator<< ( const std::string &  t  ) 

Log a string.

This is equivalent to the templated operator<<, but reduces code size since it is compiled only once.

Definition at line 476 of file Logger.cpp.

References Logger::operator<<().

Logger & operator<< ( const char *  t  ) 

Log a text message.

This is equivalent to the templated operator<<, but reduces code size since it is compiled only once.

Definition at line 460 of file Logger.cpp.

References Logger::D::inpguard, Logger::D::logline, Logger::D::maylog(), Logger::D::maylogFile(), and Logger::D::maylogStdOut().

void setLogLevel ( LogLevel  ll  ) 

Set the loglevel of the outgoing (streamed) messages.

All messages with this level or higher importance will be displayed. For example, setting to Logger::Debug will print everyting, setting to Logger::Critical will only print critical or fatal errors.

Definition at line 545 of file Logger.cpp.

References Logger::D::outloglevel.

void logflush (  ) 

Flush log buffers.

May log nothing if empty.

Definition at line 509 of file Logger.cpp.

References Logger::D::inpguard, Logger::D::maylog(), Logger::D::maylogFile(), Logger::D::maylogStdOut(), and Logger::D::stdoutput.

Referenced by Logger::operator<<(), and Logger::shutdown().

void logendl (  ) 

Add endl and flush buffers.

Will always log at least one line.

Definition at line 539 of file Logger.cpp.

References Logger::endl(), Logger::D::logit(), and Logger::D::maylog().

Referenced by Logger::operator<<().

void lognl (  ) 

Add newline without flushing buffers.

If you need to log a lot of lines, this is advised with a flush or endl at the end.

Definition at line 533 of file Logger.cpp.

References Logger::D::logit(), Logger::D::maylog(), and Logger::nl().

Referenced by Logger::operator<<().


The documentation for this class was generated from the following files:
Generated on Tue Mar 25 17:41:56 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3