#include <Logger.hpp>
Classes | |
struct | D |
struct | In |
Public Types | |
typedef std::ostream &(* | LogFunction) (std::ostream &) |
enum | LogLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime } |
Public Member Functions | |
void | allowRealTime () |
void | disallowRealTime () |
LogLevel | getLogLevel () const |
std::string | getLogLine () |
std::string | getLogModule () const |
os::TimeService::ticks | getReferenceTime () const |
Logger & | in (const std::string &modname) |
void | logendl () |
void | logflush () |
void | lognl () |
void | mayLogFile (bool tf) |
void | mayLogStdOut (bool tf) |
template<class T > | |
Logger & | operator<< (const T &t) |
Logger & | operator<< (LogLevel ll) |
Logger & | operator<< (const std::string &) |
Logger & | operator<< (const char *) |
Logger & | operator<< (std::ostream &(*pf)(std::ostream &)) |
Logger & | out (const std::string &modname) |
void | setLogLevel (LogLevel ll) |
void | setStdStream (std::ostream &stdos) |
void | shutdown () |
void | startup () |
Static Public Member Functions | |
static std::ostream & | endl (std::ostream &__os) |
static std::ostream & | flush (std::ostream &__os) |
static Logger * | Instance (std::ostream &str=std::cerr) |
static Logger & | log () |
static Logger & | log (LogLevel ll) |
static std::ostream & | nl (std::ostream &__os) |
static void | Release () |
Private Member Functions | |
Logger (std::ostream &str=std::cerr) | |
bool | mayLog () const |
bool | mayLogFile () const |
bool | mayLogStdOut () const |
~Logger () | |
Private Attributes | |
D * | d |
std::ostream & | fileline |
os::Mutex & | inpguard |
std::ostream & | logline |
Static Private Attributes | |
static Logger * | _instance = 0 |
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".
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.
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.
Enumerate all log-levels from absolute silence to everything.
Enumerator | |
---|---|
Never | |
Fatal | |
Critical | |
Error | |
Warning | |
Info | |
Debug | |
RealTime |
Definition at line 121 of file Logger.hpp.
|
private |
Definition at line 325 of file Logger.cpp.
|
private |
Definition at line 332 of file Logger.cpp.
void RTT::Logger::allowRealTime | ( | ) |
Allow messages of the LogLevel 'RealTime' to appear on the console.
Definition at line 357 of file Logger.cpp.
void RTT::Logger::disallowRealTime | ( | ) |
Disallow messages of the LogLevel 'RealTime' to appear on the console.
Definition at line 362 of file Logger.cpp.
|
static |
Definition at line 383 of file Logger.cpp.
|
static |
Flush the output stream.
Definition at line 393 of file Logger.cpp.
Logger::LogLevel RTT::Logger::getLogLevel | ( | ) | const |
Return the current output loglevel.
Definition at line 613 of file Logger.cpp.
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.
std::string RTT::Logger::getLogModule | ( | ) | const |
Get the name of the current Log generating Module.
Definition at line 432 of file Logger.cpp.
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.
Definition at line 414 of file Logger.cpp.
|
static |
Get the singleton logger.
Definition at line 75 of file Logger.cpp.
|
static |
As Instance(), but more userfriendly.
Definition at line 117 of file Logger.cpp.
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.
void RTT::Logger::logflush | ( | ) |
Flush log buffers. May log nothing if empty.
Definition at line 573 of file Logger.cpp.
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.
|
private |
Returns true if the next message will be logged. Returns false if the LogLevel is RealTime and allowRealTime() was not called or if the logger was not started.
Definition at line 337 of file Logger.cpp.
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.
|
private |
Definition at line 341 of file Logger.cpp.
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.
|
private |
Definition at line 345 of file Logger.cpp.
|
static |
Insert a newline '
' in the ostream. (Why is this not in the standard ?)
Definition at line 373 of file Logger.cpp.
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.
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.
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.
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.
Logger & RTT::Logger::out | ( | const std::string & | modname | ) |
The counterpart of in().
Definition at line 423 of file Logger.cpp.
|
static |
Delete the singleton logger.
Definition at line 82 of file Logger.cpp.
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.
void RTT::Logger::setStdStream | ( | std::ostream & | stdos | ) |
Set the standard output stream. (default is cerr).
Definition at line 518 of file Logger.cpp.
void RTT::Logger::shutdown | ( | ) |
Print a 'goodbye' string in Info, Flush all streams and stop Logging.
Definition at line 494 of file Logger.cpp.
void RTT::Logger::startup | ( | ) |
Print a 'welcome' string in Info and reset log timestamp.
Definition at line 444 of file Logger.cpp.
|
staticprivate |
Definition at line 335 of file Logger.hpp.
|
private |
Definition at line 97 of file Logger.hpp.
|
private |
Definition at line 106 of file Logger.hpp.
|
private |
These three are required to have a correct operator<<(T t) behavior for setting the stream formatting etc.
Definition at line 104 of file Logger.hpp.
|
private |
Definition at line 105 of file Logger.hpp.