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 65 #include "rtt-config.h" 71 using namespace detail;
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
135 #ifdef OROSEM_REMOTE_LOGGING
136 remotestring(ORONUM_LOGGING_BUFSIZE,
std::string(), true),
138 #if defined(OROSEM_FILE_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+
"]";
326 :d ( new
Logger::
D(str, getenv(
"ORO_LOGFILE")) ),
327 inpguard(d->inpguard), logline(d->logline), fileline(d->fileline)
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 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.";
464 xtramsg =
"Successfully extracted environment variable ORO_LOGLEVEL";
469 if ( wantedlevel < 0 )
475 *
this<<
" OROCOS version '" ORO_xstr(RTT_VERSION)
"'";
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 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 532 #
if defined(OROSEM_FILE_LOGGING) || defined(OROSEM_REMOTE_LOGGING)
565 #
if defined(OROSEM_FILE_LOGGING) || defined(OROSEM_REMOTE_LOGGING)
580 #ifndef OROSEM_PRINTF_LOGGING 584 #if defined(OROSEM_FILE_LOGGING) 586 #ifndef OROSEM_PRINTF_LOGGING 608 #if defined(OROSEM_LOG4CPP_LOGGING) 609 d->category.setPriority(level2Priority(ll));
618 #else // OROBLD_DISABLE_LOGGING Logger & out(const std::string &modname)
std::string getLogModule() const
std::string showTime() const
bool maylogStdOut() const
D(std::ostream &str, char const *logfile_name)
static nsecs ticks2nsecs(const ticks t)
TimeService::ticks timestamp
bool mayLogStdOut() const
LogLevel getLogLevel() const
std::string showLevel(LogLevel ll) const
static Logger * Instance(std::ostream &str=std::cerr)
Logger(std::ostream &str=std::cerr)
static std::ostream & nl(std::ostream &__os)
Seconds secondsSince(ticks relativeTime) const
static TimeService * Instance()
void logit(std::ostream &(*pf)(std::ostream &))
std::stringstream logline
static std::ostream & flush(std::ostream &__os)
static std::ostream & endl(std::ostream &__os)
static Logger * _instance
In(const std::string &module)
std::string showModule() const
Logger & operator<<(const T &t)
An object oriented wrapper around a non recursive mutex.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
void setStdStream(std::ostream &stdos)
Logger & in(const std::string &modname)
Logger::LogLevel intToLogLevel(int ll)
void setLogLevel(LogLevel ll)
os::TimeService::ticks getReferenceTime() const
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...