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
00051 namespace RTT
00052 {
00088 class Logger
00089 {
00090 class D;
00091 D* d;
00092 public:
00100 enum LogLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime };
00101
00105 void allowRealTime();
00106
00110 void disallowRealTime();
00111
00126 struct In {
00127 In(const char* module);
00128 ~In();
00129 const char* oldmod;
00130 };
00131
00136 Logger& in(const char* modname);
00137
00142 Logger& out();
00143
00147 const char* getLogModule() const;
00148
00153 typedef std::ostream& (*LogFunction)(std::ostream&);
00154
00158 static std::ostream& nl(std::ostream& __os);
00159
00160
00161
00162
00163 static std::ostream& endl(std::ostream& __os);
00164
00168 static std::ostream& flush(std::ostream& __os);
00169
00173 static Logger* Instance();
00174
00178 static void Release();
00179
00183 static Logger& log();
00184
00188 static Logger& log(LogLevel ll);
00189
00193 void startup();
00194
00198 void shutdown();
00199
00205 std::string getLogLine();
00206
00210 void setStdStream( std::ostream& stdos );
00211
00218 template< class T>
00219 Logger& operator<<( T t );
00220
00224 Logger& operator<<(LogLevel ll);
00225
00231 Logger& operator<<(const std::string&);
00232
00238 Logger& operator<<(const char*);
00239
00243 Logger& operator<<(std::ostream& (*pf)(std::ostream&));
00244
00252 void setLogLevel( LogLevel ll );
00253
00257 LogLevel getLogLevel() const;
00258
00262 void logflush();
00263
00268 void logendl();
00269
00275 void lognl();
00276
00277 private:
00284 bool mayLog() const;
00285
00286 Logger();
00287 ~Logger();
00288
00289 static Logger* _instance;
00290 };
00291
00299 enum LoggerLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime };
00300
00304 static inline Logger& log() { return Logger::log(); }
00305
00310 static inline Logger& log(LoggerLevel ll) { return Logger::log(Logger::LogLevel(ll)); }
00311
00316 static inline Logger::LogFunction endlog() {return Logger::endl; }
00317
00323 static inline Logger::LogFunction endlog(LoggerLevel ll) { log(ll); return Logger::endl; }
00324
00329 static inline Logger::LogFunction nlog() {return Logger::nl; }
00330
00335 static inline Logger::LogFunction flushlog() {return Logger::flush; }
00336 }
00337
00338 #include "Logger.inl"
00339
00340 #endif