Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef ORO_CORELIB_lOGGER_HPP
00040 #define ORO_CORELIB_lOGGER_HPP
00041
00042 #include "rtt-config.h"
00043 #ifndef OROBLD_DISABLE_LOGGING
00044 #include <ostream>
00045 #include <sstream>
00046 #else
00047 #include <iosfwd>
00048 #endif
00049 #include <string>
00050 #ifndef OROSEM_PRINTF_LOGGING
00051 #include <iostream>
00052 #endif
00053
00054 #include "os/TimeService.hpp"
00055 #include "os/Mutex.hpp"
00056 #include "os/MutexLock.hpp"
00057
00058 namespace RTT
00059 {
00095 class RTT_API Logger
00096 {
00097 struct D;
00098 D* d;
00104 os::Mutex& inpguard;
00105 std::ostream& logline;
00106 std::ostream& fileline;
00107 public:
00108
00112 os::TimeService::ticks getReferenceTime()const;
00113
00121 enum LogLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime };
00122
00126 void allowRealTime();
00127
00131 void disallowRealTime();
00132
00137 void mayLogStdOut(bool tf);
00138
00143 void mayLogFile(bool tf);
00144
00159 struct RTT_API In {
00160 In(const std::string& module);
00161 ~In();
00162 std::string oldmod;
00163 };
00164
00169 Logger& in(const std::string& modname);
00170
00175 Logger& out(const std::string& modname);
00176
00180 std::string getLogModule() const;
00181
00186 typedef std::ostream& (*LogFunction)(std::ostream&);
00187
00191 static std::ostream& nl(std::ostream& __os);
00192
00193
00194
00195
00196 static std::ostream& endl(std::ostream& __os);
00197
00201 static std::ostream& flush(std::ostream& __os);
00202
00210 static Logger* Instance(std::ostream& str=std::cerr);
00211
00215 static void Release();
00216
00220 static Logger& log();
00221
00225 static Logger& log(LogLevel ll);
00226
00230 void startup();
00231
00235 void shutdown();
00236
00242 std::string getLogLine();
00243
00247 void setStdStream( std::ostream& stdos );
00248
00255 template< class T>
00256 Logger& operator<<( T t );
00257
00261 Logger& operator<<(LogLevel ll);
00262
00268 Logger& operator<<(const std::string&);
00269
00275 Logger& operator<<(const char*);
00276
00280 Logger& operator<<(std::ostream& (*pf)(std::ostream&));
00281
00289 void setLogLevel( LogLevel ll );
00290
00294 LogLevel getLogLevel() const;
00295
00299 void logflush();
00300
00305 void logendl();
00306
00312 void lognl();
00313
00314 private:
00321 bool mayLog() const;
00322 bool mayLogStdOut() const;
00323 bool mayLogFile() const;
00324
00325 Logger(std::ostream& str=std::cerr);
00326 ~Logger();
00327
00328 static Logger* _instance;
00329 };
00330
00338 enum LoggerLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime };
00339
00343 static inline Logger& log() { return Logger::log(); }
00344
00349 static inline Logger& log(LoggerLevel ll) { return Logger::log(Logger::LogLevel(ll)); }
00350
00355 static inline Logger::LogFunction endlog() {return Logger::endl; }
00356
00362 static inline Logger::LogFunction endlog(LoggerLevel ll) { log(ll); return Logger::endl; }
00363
00368 static inline Logger::LogFunction nlog() {return Logger::nl; }
00369
00374 static inline Logger::LogFunction flushlog() {return Logger::flush; }
00375 }
00376
00377 #include "Logger.inl"
00378
00379 #endif