48 #ifdef OROSEM_PRINTF_LOGGING 53 # ifdef OROSEM_FILE_LOGGING 55 # ifdef OROSEM_LOG4CPP_LOGGING 56 # include <log4cpp/Category.hh> 59 # ifdef OROSEM_REMOTE_LOGGING 71 using namespace detail;
73 Logger* Logger::_instance = 0;
77 _instance =
new Logger(str);
84 _instance->shutdown();
90 #ifndef OROBLD_DISABLE_LOGGING 92 #ifdef OROSEM_LOG4CPP_LOGGING 94 const std::string Logger::log4cppCategoryName =
"org.orocos.rtt";
96 log4cpp::Priority::Value level2Priority(
const int logLevel)
98 log4cpp::Priority::Value value = log4cpp::Priority::NOTSET;
101 case Never: value = log4cpp::Priority::NOTSET;
break;
102 case Fatal: value = log4cpp::Priority::FATAL;
break;
103 case Critical: value = log4cpp::Priority::CRIT;
break;
104 case Error: value = log4cpp::Priority::ERROR;
break;
105 case Warning: value = log4cpp::Priority::WARN;
break;
106 case Info: value = log4cpp::Priority::INFO;
break;
107 case Debug: value = log4cpp::Priority::DEBUG;
break;
109 case RealTime: value = log4cpp::Priority::DEBUG;
break;
110 default: value = log4cpp::Priority::NOTSET;
break;
122 return Instance()->operator<<( ll );
131 D(std::ostream& str,
char const* logfile_name) :
132 #ifndef OROSEM_PRINTF_LOGGING
139 #if defined(OROSEM_LOG4CPP_LOGGING)
140 category(log4cpp::Category::getInstance(
RTT::
Logger::log4cppCategoryName)),
141 #elif !defined(OROSEM_PRINTF_LOGGING)
142 logfile(logfile_name ? logfile_name :
"orocos.log"),
148 started(false), showtime(true), allowRT(false),
149 mlogStdOut(true), mlogFile(true),
152 #if defined(OROSEM_FILE_LOGGING) && !defined(OROSEM_LOG4CPP_LOGGING) && defined(OROSEM_PRINTF_LOGGING) 153 logfile = fopen(logfile_name ? logfile_name :
"orocos.log",
"w");
158 if (!started || (outloglevel ==
RealTime && allowRT ==
false))
164 if ( inloglevel <= outloglevel && outloglevel !=
Never && inloglevel !=
Never && mlogStdOut)
170 if ( (inloglevel <=
Info || inloglevel <= outloglevel) && mlogFile)
180 void logit(std::ostream& (*pf)(std::ostream&))
184 std:: string res = showTime() +
" " + showLevel(inloglevel) + showModule() +
" ";
187 if ( maylogStdOut() ) {
188 #ifndef OROSEM_PRINTF_LOGGING 189 *stdoutput << res << logline.str() << pf;
191 printf(
"%s%s\n", res.c_str(), logline.str().c_str() );
196 if ( maylogFile() ) {
197 #ifdef OROSEM_FILE_LOGGING 198 #if defined(OROSEM_LOG4CPP_LOGGING) 199 category.log(level2Priority(inloglevel), fileline.str());
200 #elif !defined(OROSEM_PRINTF_LOGGING) 201 logfile << res << fileline.str() << pf;
203 fprintf( logfile,
"%s%s\n", res.c_str(), fileline.str().c_str() );
205 #ifdef OROSEM_REMOTE_LOGGING 206 remotestring.Push(res+fileline.str());
208 #if defined(OROSEM_FILE_LOGGING) || defined(OROSEM_REMOTE_LOGGING) 215 #ifndef OROSEM_PRINTF_LOGGING 219 #if defined(OROSEM_FILE_LOGGING) || defined(OROSEM_REMOTE_LOGGING) 220 std::stringstream fileline;
222 #if defined(OROSEM_REMOTE_LOGGING) 225 #if defined(OROSEM_FILE_LOGGING) 226 #if defined(OROSEM_LOG4CPP_LOGGING) 227 log4cpp::Category& category;
229 # ifndef OROSEM_PRINTF_LOGGING 230 std::ofstream logfile;
264 std::stringstream time;
309 return "["+moduleptr+
"]";
325 Logger::Logger(std::ostream& str)
326 :d ( new
Logger::
D(str, getenv(
"ORO_LOGFILE")) ),
327 inpguard(d->inpguard), logline(d->logline), fileline(d->fileline)
337 bool Logger::mayLog()
const {
341 bool Logger::mayLogFile()
const {
342 return d->maylogFile();
345 bool Logger::mayLogStdOut()
const {
346 return d->maylogStdOut();
349 void Logger::mayLogStdOut(
bool tf) {
353 void Logger::mayLogFile(
bool tf) {
375 #ifndef OROSEM_PRINTF_LOGGING 376 return __os.put(__os.widen(
'\n'));
385 #ifndef OROSEM_PRINTF_LOGGING 386 return flush(__os.put(__os.widen(
'\n')));
395 #ifndef OROSEM_PRINTF_LOGGING 419 d->moduleptr = modname.c_str();
428 d->moduleptr = oldmod.c_str();
436 std::string ret = d->moduleptr.c_str();
441 #define ORO_xstr(s) ORO_str(s) 442 #define ORO_str(s) #s 447 #ifndef OROBLD_DISABLE_LOGGING 448 std::string xtramsg =
"No ORO_LOGLEVEL environment variable set.";
453 if ( getenv(
"ORO_LOGLEVEL" ) != 0 ) {
454 std::stringstream conv;
455 conv.str( std::string( getenv(
"ORO_LOGLEVEL" ) ) );
458 xtramsg = std::string(
"Failed to extract loglevel from environment variable ORO_LOGLEVEL.")
459 +
" It contained the string '"+conv.str()+
"', while it should contain an integer value.";
463 d->outloglevel = d->intToLogLevel(wantedlevel);
464 xtramsg =
"Successfully extracted environment variable ORO_LOGLEVEL";
469 if ( wantedlevel < 0 )
477 *
this <<
" compiled with GCC " ORO_xstr(__GNUC__)
"." ORO_xstr(__GNUC_MINOR__)
"." ORO_xstr(__GNUC_PATCHLEVEL__)
".";
479 #ifdef OROPKG_OS_LXRT 482 #ifdef OROPKG_OS_GNULINUX 485 #ifdef OROPKG_OS_XENOMAI 488 *
this<<
"Orocos Logging Activated at level : " << d->showLevel( d->outloglevel ) <<
" ( "<<int(d->outloglevel)<<
" ) "<<
Logger::nl;
490 *
this<<
"Logging is relative to this time." <<
Logger::endl;
503 #ifdef OROSEM_REMOTE_LOGGING 509 if(d->remotestring.Pop(line))
519 #ifndef OROSEM_PRINTF_LOGGING 520 d->stdoutput = &stdos;
529 if ( d->maylogStdOut() )
534 if ( d->maylogFile() )
563 if ( d->maylogStdOut() )
566 if ( d->maylogFile() )
579 if ( d->maylogStdOut() ) {
580 #ifndef OROSEM_PRINTF_LOGGING 581 d->stdoutput->flush();
584 #if defined(OROSEM_FILE_LOGGING) 585 if ( d->maylogFile() ) {
586 #ifndef OROSEM_PRINTF_LOGGING 608 #if defined(OROSEM_LOG4CPP_LOGGING) 609 d->category.setPriority(level2Priority(ll));
614 return d->outloglevel ;
618 #else // OROBLD_DISABLE_LOGGING 620 Logger::Logger(std::ostream& )
Logger & out(const std::string &modname)
The counterpart of in().
std::string getLogModule() const
Get the name of the current Log generating Module.
std::string showTime() const
bool maylogStdOut() const
D(std::ostream &str, char const *logfile_name)
double Seconds
Seconds are stored as a double precision float.
A Lock-free buffer implementation to read and write data of type T in a FIFO way. ...
#define ORONUM_LOGGING_BUFSIZE
static nsecs ticks2nsecs(const ticks t)
Convert an amount of ticks to nano seconds.
TimeService::ticks timestamp
LogLevel getLogLevel() const
Return the current output loglevel.
std::string showLevel(LogLevel ll) const
Convert a loglevel to a string representation.
long long ticks
The type for the systems clock tick.
static Logger * Instance(std::ostream &str=std::cerr)
Get the singleton logger.
void shutdown()
Print a 'goodbye' string in Info, Flush all streams and stop Logging.
#define OROSEM_FILE_LOGGING
static std::ostream & nl(std::ostream &__os)
Insert a newline ' ' in the ostream.
#define OROSEM_REMOTE_LOGGING
This hidden struct stores all data structures required for logging.
Logger & operator<<(const T &t)
Send (user defined) data into this logger.
void logflush()
Flush log buffers.
Seconds secondsSince(ticks relativeTime) const
Get Seconds passed since a certain moment.
A simple logging class to debug/ analyse what is going on in the Orocos system.
static TimeService * Instance()
void logit(std::ostream &(*pf)(std::ostream &))
This function is called when a new message is ready to be written to screen, disk, or stream.
std::stringstream logline
void startup()
Print a 'welcome' string in Info and reset log timestamp.
std::string getLogLine()
This method gets all messages upto level Info and can be freely read by the user, removing the line f...
void disallowRealTime()
Disallow messages of the LogLevel 'RealTime' to appear on the console.
static std::ostream & flush(std::ostream &__os)
Flush the output stream.
static std::ostream & endl(std::ostream &__os)
void lognl()
Add newline without flushing buffers.
In(const std::string &module)
std::string showModule() const
LogLevel
Enumerate all log-levels from absolute silence to everything.
static Logger & log()
As Instance(), but more userfriendly.
void allowRealTime()
Allow messages of the LogLevel 'RealTime' to appear on the console.
static void Release()
Delete the singleton logger.
An object oriented wrapper around a non recursive mutex.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
void setStdStream(std::ostream &stdos)
Set the standard output stream.
void logendl()
Add endl and flush buffers.
Logger & in(const std::string &modname)
Inform the Logger of the entry of a module.
Logger::LogLevel intToLogLevel(int ll)
void setLogLevel(LogLevel ll)
Set the loglevel of the outgoing (streamed) messages.
os::TimeService::ticks getReferenceTime() const
Function to get the loggers starting timestamp.
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
ticks getTicks() const
Get current tick of the System clock.