StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Logger.hpp
Go to the documentation of this file.
00001 #ifndef __STDAIR_SVC_LOGGER_HPP
00002 #define __STDAIR_SVC_LOGGER_HPP
00003 
00004 // //////////////////////////////////////////////////////////////////////
00005 // Import section
00006 // //////////////////////////////////////////////////////////////////////
00007 // STL
00008 #include <cassert>
00009 #include <sstream>
00010 #include <string>
00011 // StdAir
00012 #include <stdair/stdair_log.hpp>
00013 #include <stdair/basic/BasLogParams.hpp>
00014 
00015 // /////////////// LOG MACROS /////////////////
00016 #define STDAIR_LOG_CORE(iLevel, iToBeLogged) \
00017   { std::ostringstream ostr; ostr << iToBeLogged; \
00018     stdair::Logger::instance().log (iLevel, __LINE__, __FILE__, ostr.str()); }
00019 
00020 #define STDAIR_LOG_CRITICAL(iToBeLogged) \
00021   STDAIR_LOG_CORE (stdair::LOG::CRITICAL, iToBeLogged)
00022 
00023 #define STDAIR_LOG_ERROR(iToBeLogged) \
00024   STDAIR_LOG_CORE (stdair::LOG::ERROR, iToBeLogged)
00025 
00026 #define STDAIR_LOG_NOTIFICATION(iToBeLogged) \
00027   STDAIR_LOG_CORE (stdair::LOG::NOTIFICATION, iToBeLogged)
00028 
00029 #define STDAIR_LOG_WARNING(iToBeLogged) \
00030   STDAIR_LOG_CORE (stdair::LOG::WARNING, iToBeLogged)
00031 
00032 #define STDAIR_LOG_DEBUG(iToBeLogged) \
00033   STDAIR_LOG_CORE (stdair::LOG::DEBUG, iToBeLogged)
00034 
00035 #define STDAIR_LOG_VERBOSE(iToBeLogged) \
00036   STDAIR_LOG_CORE (stdair::LOG::VERBOSE, iToBeLogged)
00037 // /////////// (END OF) LOG MACROS /////////////
00038 
00039 
00040 namespace stdair {
00041 
00048   class Logger {
00050     friend class FacSupervisor;
00051     friend class STDAIR_Service;
00052 
00053   public:
00054     
00058     template <typename T>
00059     void log (const LOG::EN_LogLevel iLevel, const int iLineNumber,
00060               const std::string& iFileName, const T& iToBeLogged) {
00061       assert (_logStream != NULL);
00062       if (iLevel <= _level) {
00063         *_logStream << "[" << LOG::_logLevels[iLevel] << "]" << iFileName << ":"
00064                     << iLineNumber << ": " << iToBeLogged << std::endl;
00065       }
00066     }
00067     
00071     static Logger& instance();
00072     
00073 
00074   private:
00075     // /////////////////// Initialisation and finalisation ////////////////
00079     bool getStatus() const {
00080       return _hasBeenInitialised;
00081     }
00082 
00086     void setLevel (const LOG::EN_LogLevel& iLevel) {
00087       _level = iLevel;
00088     }
00089 
00093     void setStream (std::ostream& ioStream) {
00094       _logStream = &ioStream;
00095     }
00096 
00100     void setStatus (const bool iStatus) {
00101       _hasBeenInitialised = iStatus;
00102     }
00103 
00108     Logger();
00112     Logger (const Logger&);
00116     ~Logger();
00117 
00123     static void init (const BasLogParams&);
00124 
00128     static BasLogParams getLogParams();
00129 
00133     static void clean();
00134 
00135 
00136   private:
00137     // /////////////////// Attributes ////////////////
00141     LOG::EN_LogLevel _level;
00142     
00146     std::ostream* _logStream;
00147 
00151     bool _hasBeenInitialised;
00152   };
00153   
00154 }
00155 #endif // __STDAIR_SVC_LOGGER_HPP
00156