$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/service/Logger.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <iostream>
00006 // StdAir Logger
00007 #include <stdair/stdair_exceptions.hpp>
00008 #include <stdair/service/Logger.hpp>
00009 
00010 namespace stdair {
00011   
00012   // //////////////////////////////////////////////////////////////////////
00013   Logger::Logger()
00014     : _level (LOG::DEBUG), _logStream (&std::cout),
00015       _hasBeenInitialised (false) {
00016   }
00017 
00018   // //////////////////////////////////////////////////////////////////////
00019   Logger::Logger (const Logger&)
00020     : _level (LOG::DEBUG), _logStream (&std::cout),
00021       _hasBeenInitialised (false) {
00022     assert (false);
00023   }
00024 
00025   // //////////////////////////////////////////////////////////////////////
00026   Logger::~Logger() {
00027     // std::cout << "In Logger destructor" << std::endl;
00028   }
00029 
00030   // //////////////////////////////////////////////////////////////////////
00031   void Logger::init (const BasLogParams& iLogParams) {
00032 
00033     //
00034     Logger& lInstance = instance();
00035     const bool hasBeenInitialised = lInstance.getStatus();
00036     if (hasBeenInitialised == true
00037         && iLogParams.getForcedInitialisationFlag() == false) {
00038       STDAIR_LOG_ERROR ("Error: the log stream has already been initialised");
00039       assert (false);
00040     }
00041 
00042     lInstance.setLevel (iLogParams._logLevel);
00043     lInstance.setStream (iLogParams._logStream);
00044     lInstance.setStatus (true);
00045   }
00046 
00047   // //////////////////////////////////////////////////////////////////////
00048   Logger& Logger::instance() {
00049     static Logger _instance;
00050     return _instance;
00051   }
00052   
00053   // //////////////////////////////////////////////////////////////////////
00054   BasLogParams Logger::getLogParams() {
00055     std::ostream* oStream_ptr = instance()._logStream;
00056     assert (oStream_ptr != NULL);
00057     return BasLogParams (instance()._level, *oStream_ptr);
00058   }
00059 
00060   // //////////////////////////////////////////////////////////////////////
00061   void Logger::clean() {
00062     Logger& lInstance = instance();
00063     lInstance.setStatus (false);
00064   }
00065   
00066 }