Orocos Real-Time Toolkit  2.8.3
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
RTT::Logger Class Reference

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

#include <rtt/Logger.hpp>

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...
 

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. More...
 

Public Member Functions

os::TimeService::ticks getReferenceTime () const
 Function to get the loggers starting timestamp. More...
 
void allowRealTime ()
 Allow messages of the LogLevel 'RealTime' to appear on the console. More...
 
void disallowRealTime ()
 Disallow messages of the LogLevel 'RealTime' to appear on the console. More...
 
void mayLogStdOut (bool tf)
 Toggles the flag if the logger may log to the standard output stream. More...
 
void mayLogFile (bool tf)
 Toggles the flag if the logger may log to the file stream. More...
 
Loggerin (const std::string &modname)
 Inform the Logger of the entry of a module. More...
 
Loggerout (const std::string &modname)
 The counterpart of in(). More...
 
std::string getLogModule () const
 Get the name of the current Log generating Module. More...
 
void startup ()
 Print a 'welcome' string in Info and reset log timestamp. More...
 
void shutdown ()
 Print a 'goodbye' string in Info, Flush all streams and stop Logging. More...
 
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. More...
 
void setStdStream (std::ostream &stdos)
 Set the standard output stream. More...
 
template<class T >
Loggeroperator<< (const T &t)
 Send (user defined) data into this logger. More...
 
Loggeroperator<< (LogLevel ll)
 Set the loglevel of the incomming messages. More...
 
Loggeroperator<< (const std::string &)
 Log a string. More...
 
Loggeroperator<< (const char *)
 Log a text message. More...
 
Loggeroperator<< (std::ostream &(*pf)(std::ostream &))
 Catch the std::endl and other stream manipulators. More...
 
void setLogLevel (LogLevel ll)
 Set the loglevel of the outgoing (streamed) messages. More...
 
LogLevel getLogLevel () const
 Return the current output loglevel. More...
 
void logflush ()
 Flush log buffers. More...
 
void logendl ()
 Add endl and flush buffers. More...
 
void lognl ()
 Add newline without flushing buffers. More...
 

Static Public Member Functions

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

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 95 of file Logger.hpp.

Member Typedef Documentation

typedef std::ostream&(* RTT::Logger::LogFunction) (std::ostream &)

Function signature of the functions that influence the log stream.

Definition at line 186 of file Logger.hpp.

Member Enumeration Documentation

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 121 of file Logger.hpp.

Member Function Documentation

void RTT::Logger::allowRealTime ( )

Allow messages of the LogLevel 'RealTime' to appear on the console.

Definition at line 357 of file Logger.cpp.

References endl(), and Warning.

Referenced by operator<<().

void RTT::Logger::disallowRealTime ( )

Disallow messages of the LogLevel 'RealTime' to appear on the console.

Definition at line 362 of file Logger.cpp.

References endl(), and Warning.

Referenced by operator<<().

std::ostream & RTT::Logger::endl ( std::ostream &  __os)
static

Definition at line 383 of file Logger.cpp.

References flush().

Referenced by __os_exit(), __os_init(), RTT::types::TypeInfoRepository::addType(), allowRealTime(), RTT::internal::OperationCallerC::arg(), RTT::internal::SendHandleC::arg(), RTT::internal::OperationCallerC::call(), RTT::scripting::ScriptingService::clear(), RTT::internal::SendHandleC::collect(), RTT::internal::SendHandleC::collectIfDone(), RTT::extras::composeProperty(), RTT::types::composeTemplateProperty(), RTT::types::TemplateCompositionFactory< bool >::composeType(), RTT::types::SequenceTypeInfoBase< std::vector< double > >::composeType(), RTT::scripting::ParsedStateMachine::copy(), RTT::corba::AnyConversion< Type >::createAny(), RTT::scripting::StateMachine::createEventTransition(), disallowRealTime(), RTT::scripting::StatementProcessor::execute(), RTT::extras::SimulationThread::finalize(), RTT::corba::DataSourceProxy< T >::get(), RTT::corba::ValueDataSourceProxy< T >::get(), RTT::types::TypekitRepository::Import(), RTT::extras::SimulationThread::initialize(), RTT::scripting::ScriptingService::loadFunctions(), RTT::scripting::ScriptingService::loadPrograms(), RTT::scripting::ScriptingService::loadStateMachines(), logendl(), RTT::types::TypeInfoRepository::logTypeInfo(), operator<<(), RTT::scripting::ProgramGraphParser::parserUsed(), RTT::os::rtai_thread_wrapper(), RTT::scripting::ScriptingService::runScript(), RTT::internal::OperationCallerC::send(), shutdown(), RTT::extras::SimulationThread::SimulationThread(), RTT::extras::IRQActivity::start(), RTT::extras::SlaveActivity::start(), startup(), RTT::corba::AnyConversion< Type >::toCorbaType(), RTT::corba::AnyConversion< Type >::toStdType(), RTT::scripting::ScriptingService::unloadProgram(), RTT::scripting::ScriptingService::unloadStateMachine(), RTT::corba::AnyConversion< Type >::update(), RTT::corba::AnyConversion< Type >::updateAny(), RTT::updateProperties(), RTT::scripting::ValueChangeParser::ValueChangeParser(), and warn_upon_switch().

std::ostream & RTT::Logger::flush ( std::ostream &  __os)
static

Flush the output stream.

Definition at line 393 of file Logger.cpp.

Referenced by endl(), and operator<<().

Logger::LogLevel RTT::Logger::getLogLevel ( ) const

Return the current output loglevel.

Definition at line 613 of file Logger.cpp.

Referenced by operator<<().

std::string RTT::Logger::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.

Definition at line 502 of file Logger.cpp.

Referenced by operator<<().

std::string RTT::Logger::getLogModule ( ) const

Get the name of the current Log generating Module.

Definition at line 432 of file Logger.cpp.

Referenced by operator<<().

TimeService::ticks RTT::Logger::getReferenceTime ( ) const

Function to get the loggers starting timestamp.

Definition at line 367 of file Logger.cpp.

Logger & RTT::Logger::in ( const std::string &  modname)

Inform the Logger of the entry of a module.

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

Definition at line 414 of file Logger.cpp.

Referenced by RTT::Logger::In::In(), and operator<<().

Logger * RTT::Logger::Instance ( std::ostream &  str = std::cerr)
static

Get the singleton logger.

Postcondition
If the singleton did not already exist then it is created and associated with the given ostream. If the singleton already existed then no change occurs (and the singleton remains associated with its existing ostream).

Definition at line 75 of file Logger.cpp.

Logger & RTT::Logger::log ( )
static

As Instance(), but more userfriendly.

Definition at line 117 of file Logger.cpp.

Referenced by __os_exit(), __os_init(), RTT::internal::OperationCallerC::arg(), RTT::internal::SendHandleC::arg(), RTT::internal::OperationCallerC::call(), RTT::scripting::ScriptingService::clear(), RTT::internal::SendHandleC::collect(), RTT::internal::SendHandleC::collectIfDone(), RTT::extras::composeProperty(), RTT::types::composeTemplateProperty(), RTT::types::TemplateCompositionFactory< bool >::composeType(), RTT::types::SequenceTypeInfoBase< std::vector< double > >::composeType(), RTT::scripting::ParsedStateMachine::copy(), RTT::corba::AnyConversion< Type >::createAny(), RTT::scripting::StateMachine::createEventTransition(), RTT::corba::TaskContextProxy::DestroyOrb(), RTT::scripting::StatementProcessor::execute(), RTT::corba::TaskContextProxy::fetchServices(), RTT::extras::SimulationThread::finalize(), RTT::corba::DataSourceProxy< T >::get(), RTT::corba::ValueDataSourceProxy< T >::get(), RTT::Logger::In::In(), RTT::corba::TaskContextProxy::initFromURIOrTaskname(), RTT::extras::SimulationThread::initialize(), RTT::corba::ApplicationServer::InitOrb(), RTT::scripting::ScriptingService::loadFunctions(), RTT::scripting::ScriptingService::loadPrograms(), RTT::scripting::ScriptingService::loadStateMachines(), RTT::types::TypeInfoRepository::logTypeInfo(), operator<<(), RTT::scripting::ProgramGraphParser::parserUsed(), RTT::os::rtai_thread_wrapper(), RTT::scripting::ScriptingService::runScript(), RTT::internal::OperationCallerC::send(), RTT::extras::SimulationThread::SimulationThread(), RTT::extras::IRQActivity::start(), RTT::extras::SlaveActivity::start(), RTT::corba::TaskContextProxy::TaskContextProxy(), RTT::corba::AnyConversion< Type >::toCorbaType(), RTT::corba::AnyConversion< Type >::toStdType(), RTT::scripting::ScriptingService::unloadProgram(), RTT::scripting::ScriptingService::unloadStateMachine(), RTT::corba::AnyConversion< Type >::update(), RTT::corba::AnyConversion< Type >::updateAny(), RTT::updateProperties(), RTT::scripting::ValueChangeParser::ValueChangeParser(), warn_upon_switch(), and RTT::Logger::In::~In().

Logger & RTT::Logger::log ( LogLevel  ll)
static

As log(), but also specify the LogLevel of the next message.

Definition at line 121 of file Logger.cpp.

void RTT::Logger::logendl ( )

Add endl and flush buffers.

Will always log at least one line.

Definition at line 600 of file Logger.cpp.

References endl().

Referenced by operator<<().

void RTT::Logger::logflush ( )

Flush log buffers.

May log nothing if empty.

Definition at line 573 of file Logger.cpp.

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

void RTT::Logger::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 594 of file Logger.cpp.

References nl().

Referenced by operator<<().

void RTT::Logger::mayLogFile ( bool  tf)

Toggles the flag if the logger may log to the file stream.

Definition at line 353 of file Logger.cpp.

Referenced by operator<<().

void RTT::Logger::mayLogStdOut ( bool  tf)

Toggles the flag if the logger may log to the standard output stream.

Definition at line 349 of file Logger.cpp.

Referenced by operator<<().

std::ostream & RTT::Logger::nl ( std::ostream &  __os)
static
template<class T >
Logger & RTT::Logger::operator<< ( const T &  t)

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 15 of file Logger.inl.

References allowRealTime(), disallowRealTime(), endl(), flush(), getLogLevel(), getLogLine(), getLogModule(), RTT::Logger::In::In(), in(), log(), logendl(), logflush(), lognl(), mayLogFile(), mayLogStdOut(), Never, nl(), out(), setLogLevel(), setStdStream(), shutdown(), startup(), and RTT::Logger::In::~In().

Referenced by operator<<().

Logger & RTT::Logger::operator<< ( LogLevel  ll)

Set the loglevel of the incomming messages.

Definition at line 544 of file Logger.cpp.

Logger & RTT::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 540 of file Logger.cpp.

References operator<<().

Logger & RTT::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 524 of file Logger.cpp.

References OROSEM_FILE_LOGGING, and OROSEM_REMOTE_LOGGING.

Logger & RTT::Logger::operator<< ( std::ostream &(*)(std::ostream &)  pf)

Catch the std::endl and other stream manipulators.

Definition at line 551 of file Logger.cpp.

References endl(), flush(), logendl(), logflush(), lognl(), nl(), OROSEM_FILE_LOGGING, and OROSEM_REMOTE_LOGGING.

Logger & RTT::Logger::out ( const std::string &  modname)

The counterpart of in().

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

Definition at line 423 of file Logger.cpp.

Referenced by operator<<(), and RTT::Logger::In::~In().

void RTT::Logger::Release ( )
static

Delete the singleton logger.

Definition at line 82 of file Logger.cpp.

References RTT::Critical, RTT::Debug, RTT::Error, RTT::Fatal, RTT::Info, RTT::Never, RTT::RealTime, and RTT::Warning.

Referenced by __os_exit().

void RTT::Logger::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 606 of file Logger.cpp.

Referenced by operator<<().

void RTT::Logger::setStdStream ( std::ostream &  stdos)

Set the standard output stream.

(default is cerr).

Definition at line 518 of file Logger.cpp.

Referenced by operator<<().

void RTT::Logger::shutdown ( )

Print a 'goodbye' string in Info, Flush all streams and stop Logging.

Definition at line 494 of file Logger.cpp.

References endl(), Info, and logflush().

Referenced by operator<<().

void RTT::Logger::startup ( )

Print a 'welcome' string in Info and reset log timestamp.

Definition at line 444 of file Logger.cpp.

References endl(), Error, RTT::os::TimeService::getTicks(), Info, RTT::os::TimeService::Instance(), nl(), RTT::NSECS_IN_SECS, ORO_xstr, RTT_VERSION, and RTT::os::TimeService::ticks2nsecs().

Referenced by operator<<().


The documentation for this class was generated from the following files: