00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : LoggerManager 00006 * Package : Zeus.ZeusBase.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef LoggerManagerH 00033 #define LoggerManagerH 00034 00035 #include <zeusbase/System/Logger.h> 00036 #include <zeusbase/System/StringMap.hpp> 00037 #include <zeusbase/System/Interfaces/ILogger.hpp> 00038 00039 #define LoggerManager NAMESPACE_Zeus::TLoggerManager::getInstance() 00040 #define RootLogger LoggerManager.getRoot() 00041 00042 //For LOG_Service with Log4CXX the define is used already 00043 #ifndef LOG_SERVICE_LOG4CXX 00044 #define Logger(name) LoggerManager.getLogger(name) 00045 #endif 00046 00047 BEGIN_NAMESPACE_Zeus 00048 00049 class TCriticalSection; 00050 00051 /**************************************************************************/ 00054 /**************************************************************************/ 00055 zeusbase_class TLoggerManager : public TZObject 00056 { 00057 public: 00058 static TLoggerManager& getInstance(); 00059 00060 TLogger& getRoot(); 00061 TLogger& getLogger(const TString& strName); 00062 00063 void setRootLogger(ILogger* pLogger); 00064 void releaseAllLoggers(); 00065 Retval initLogger(TString strModuleName); 00066 00067 private: 00069 static TAutoPtr<TLoggerManager> m_ptrInstance; 00071 TLogger m_RootLogger; 00073 TStringMap<TLogger> m_mapLogger; 00075 TCriticalSection& m_rLock; 00076 00078 //Compiler problem on older version from microsoft 00079 #ifdef _MSC_VER 00080 public: 00081 #endif 00082 00083 00084 TLoggerManager(); 00085 virtual ~TLoggerManager(); 00086 00087 }; 00088 00089 /***************************************************************************/ 00092 /***************************************************************************/ 00093 inline TLoggerManager& TLoggerManager::getInstance() 00094 { 00095 return *m_ptrInstance; 00096 } 00097 00098 /***************************************************************************/ 00101 /***************************************************************************/ 00102 inline TLogger& TLoggerManager::getRoot() 00103 { 00104 return m_RootLogger; 00105 } 00106 00107 00108 END_NAMESPACE_Zeus 00109 00110 #endif