Logger.hpp
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 "TimeService.hpp"
00055
00056 namespace RTT
00057 {
00093 class RTT_API Logger
00094 {
00095 class D;
00096 D* d;
00097 public:
00098
00102 TimeService::ticks getReferenceTime()const;
00103
00111 enum LogLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime };
00112
00116 void allowRealTime();
00117
00121 void disallowRealTime();
00122
00127 void mayLogStdOut(bool tf);
00128
00133 void mayLogFile(bool tf);
00134
00149 struct RTT_API In {
00150 In(const std::string& module);
00151 ~In();
00152 std::string oldmod;
00153 };
00154
00159 Logger& in(const std::string& modname);
00160
00165 Logger& out(const std::string& modname);
00166
00170 std::string getLogModule() const;
00171
00176 typedef std::ostream& (*LogFunction)(std::ostream&);
00177
00181 static std::ostream& nl(std::ostream& __os);
00182
00183
00184
00185
00186 static std::ostream& endl(std::ostream& __os);
00187
00191 static std::ostream& flush(std::ostream& __os);
00192
00200 static Logger* Instance(std::ostream& str=std::cerr);
00201
00205 static void Release();
00206
00210 static Logger& log();
00211
00215 static Logger& log(LogLevel ll);
00216
00220 void startup();
00221
00225 void shutdown();
00226
00232 std::string getLogLine();
00233
00237 void setStdStream( std::ostream& stdos );
00238
00245 template< class T>
00246 Logger& operator<<( T t );
00247
00251 Logger& operator<<(LogLevel ll);
00252
00258 Logger& operator<<(const std::string&);
00259
00265 Logger& operator<<(const char*);
00266
00270 Logger& operator<<(std::ostream& (*pf)(std::ostream&));
00271
00279 void setLogLevel( LogLevel ll );
00280
00284 LogLevel getLogLevel() const;
00285
00289 void logflush();
00290
00295 void logendl();
00296
00302 void lognl();
00303
00304 private:
00311 bool mayLog() const;
00312
00313 Logger(std::ostream& str=std::cerr);
00314 ~Logger();
00315
00316 static Logger* _instance;
00317 };
00318
00326 enum LoggerLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime };
00327
00331 static inline Logger& log() { return Logger::log(); }
00332
00337 static inline Logger& log(LoggerLevel ll) { return Logger::log(Logger::LogLevel(ll)); }
00338
00343 static inline Logger::LogFunction endlog() {return Logger::endl; }
00344
00350 static inline Logger::LogFunction endlog(LoggerLevel ll) { log(ll); return Logger::endl; }
00351
00356 static inline Logger::LogFunction nlog() {return Logger::nl; }
00357
00362 static inline Logger::LogFunction flushlog() {return Logger::flush; }
00363 }
00364
00365 #include "Logger.inl"
00366
00367 #endif