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 #ifndef OROSEM_PRINTF_LOGGING
00051 #include <iostream>            // for std::cerr
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          * Insert a newline '\n' in the ostream and flush. (Copy of the standard)
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
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3