StdLog2.cpp
Go to the documentation of this file.
00001 /*
00002  * Non-realtime implementation of the log factory.
00003  * Wouter Caarls <w.caarls@tudelft.nl>
00004  */
00005 
00006 #ifdef MSC_VER
00007 #include <win32_compat.h>
00008 #endif
00009 
00010 #include <pthread.h>
00011 #include <threemxl/platform/io/logging/StdLog.h>
00012 #include <threemxl/platform/io/logging/Log2.h>
00013 
00014 class CStdLog2Factory : public CLog2Factory
00015 {
00016         protected:
00017                 pthread_mutex_t                                                         mMutexLogLock;
00018 
00019         public:
00020                 CStdLog2Factory()       { pthread_mutex_init(&mMutexLogLock, NULL); }
00021                 ~CStdLog2Factory()      { pthread_mutex_destroy(&mMutexLogLock); }
00022                 
00023                 virtual CLogStream &getLog(const std::string &name)
00024                 {
00025                         if (mLogs.find(name) == mLogs.end())
00026                         {
00027                                 CStdLogStream *log = new CStdLogStream(&mMutexLogLock);
00028                                 log->setHeaderText(LOG2HDRDELIMLEFT + name + LOG2HDRDELIMRIGHT);
00029                                 log->setHeaderColor(CONSL_INTENSITY);
00030                                 log->setLevel(mLevel);
00031                                 log->enableTimeStamping(mTimeStamping);
00032                                 mLogs[name] = log;
00033 
00034                                 equalizeHeaderTexts();
00035 
00036                                 return *log;
00037                         }
00038                         else
00039                                 return *mLogs[name];
00040                 }
00041 };
00042 
00043 // We use lazy initialization for the log factory
00044 // Since static local objects are constructed the first time control flows over their declaration (only),
00045 // the new logfactory will only be created once: the first time gLogFactory() is called.
00046 CLog2Factory& gLogFactory()
00047 {
00048         // WARNING: to avoid a static *de*initialization disaster, one should not use gLogFactory() in the destructor of static objects. However, this is unlikely. If so, initialize a static pointer with 'new' and return *logfact.
00049         static CStdLog2Factory logfact;
00050         return logfact;
00051 }


threemxl
Author(s):
autogenerated on Fri Aug 28 2015 13:21:08