Logger.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 10 15:59:16 CET 2005  Logger.hpp 
00003 
00004                         Logger.hpp -  description
00005                            -------------------
00006     begin                : Mon January 10 2005
00007     copyright            : (C) 2005 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009  
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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          * Insert a newline '\n' in the ostream and flush. (Copy of the standard)
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

Generated on Tue Mar 25 17:41:47 2008 for OrocosReal-TimeToolkit by  doxygen 1.5.3