log_manager.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00034 #include "gpucalc/log_manager.h"
00035 
00036 namespace gpucalc
00037 {
00038  template<> LogManager * Singleton<LogManager>::mSingleton = 0;
00039 
00040 
00041  LogManager * LogManager::getSingletonPtr()
00042  {
00043   return mSingleton;
00044  }
00045 
00046 
00047  LogManager & LogManager::getSingleton()
00048  {
00049   assert(mSingleton);
00050   return(* mSingleton);
00051  }
00052 
00053 
00054  LogManager::LogManager(): Singleton<LogManager>(_LogManagerObjectName), mLogMap(), mDefaultLog(0)
00055  {
00056  }
00057 
00058 
00059  LogManager::~LogManager()
00060  {
00061   clearContainer(mLogMap);
00062  }
00063 
00064 
00065  Log * LogManager::createLog(const std::string & name, bool defaultLog, unsigned int LogClassNameAlignment, unsigned int LogObjectNameAlignment,
00066   bool DebugOutput, bool SuppressFileOutput, bool SuppressObjectInfo)
00067  {
00068   Log * newLog = new Log(name, LogClassNameAlignment, LogObjectNameAlignment, DebugOutput, SuppressFileOutput, SuppressObjectInfo);
00069   if( !mDefaultLog || defaultLog )
00070   {
00071    mDefaultLog = newLog;
00072   }
00073   addToContainer(newLog, name, mLogMap);
00074   return newLog;
00075  }
00076 
00077 
00078  Log * LogManager::getDefaultLog()
00079  {
00080   return mDefaultLog;
00081  }
00082 
00083 
00084  Log * LogManager::setDefaultLog(Log * newLog)
00085  {
00086   Log * oldLog = mDefaultLog;
00087   mDefaultLog = newLog;
00088   return oldLog;
00089  }
00090 
00091 
00092  Log * LogManager::getLog(const std::string & name)
00093  {
00094   LogMap::iterator i = mLogMap.find(name);
00095   if (i != mLogMap.end())
00096   {
00097    return i->second;
00098   }
00099   else
00100   {
00101    Except<ERR_INVALIDPARAMS>(this, "Log not found. ", "LogManager::getLog", __FILE__, __LINE__);
00102    return NULL;
00103   }
00104  }
00105 
00106 
00107  void LogManager::destroyLog(const std::string & name)
00108  {
00109   LogMap::iterator i = mLogMap.find(name);
00110   if (i != mLogMap.end())
00111   {
00112    if (mDefaultLog == i->second)
00113    {
00114     mDefaultLog = NULL;
00115    }
00116    delete i->second;
00117    mLogMap.erase(i);
00118   }
00119 
00121   if (!mDefaultLog && !mLogMap.empty())
00122   {
00123    mDefaultLog = mLogMap.begin()->second;
00124   }
00125  }
00126 
00127 
00128  void LogManager::destroyLog(Log * log)
00129  {
00130   destroyLog(log->getObjectName());
00131  }
00132 
00133 
00134  void LogManager::logMessage(const Object & object, const std::string & Message,
00135   LogMessageLevel lml, bool maskDebug)
00136  {
00137   if (mDefaultLog)
00138   {
00139    mDefaultLog->logMessage(object, Message, lml, maskDebug);
00140   }
00141  }
00142 
00143  
00144  
00145  void LogManager::logMessage(const Object * object, const std::string & Message,
00146   LogMessageLevel lml, bool maskDebug)
00147  {
00148   if (mDefaultLog)
00149   {
00150    mDefaultLog->logMessage(object, Message, lml, maskDebug);
00151   }
00152  }
00153 
00154 
00155  void LogManager::logMessage(const std::string & LogId, const Object * object, const std::string & Message,
00156   LogMessageLevel lml, bool maskDebug)
00157  {
00158   LogMap::iterator i = mLogMap.find(LogId);
00159   if (i != mLogMap.end())
00160   {
00161    i->second->logMessage(object, Message, lml, maskDebug);
00162   }
00163   else
00164   {
00165    Except<ERR_ITEM_NOT_FOUND>(this, "Log with Id \"" + LogId + "\" cannot be found.", "LogManager::logMessage()", __FILE__, __LINE__);
00166   }
00167  }
00168 
00169  void LogManager::logMessage(const std::string & LogId, const Object & object, const std::string & Message,
00170   LogMessageLevel lml, bool maskDebug)
00171  {
00172   LogMap::iterator i = mLogMap.find(LogId);
00173   if (i != mLogMap.end())
00174   {
00175    i->second->logMessage(object, Message, lml, maskDebug);
00176   }
00177   else
00178   {
00179    Except<ERR_ITEM_NOT_FOUND>(this, "Log with Id \"" + LogId + "\" cannot be found.", "LogManager::logMessage()", __FILE__, __LINE__);
00180   }
00181  }
00182 
00183 
00184 
00185  void LogManager::setLogDetail(LoggingLevel ll)
00186  {
00187   if (mDefaultLog)
00188   {
00189    mDefaultLog->setLogDetail(ll);
00190   }
00191  }
00192 
00193 
00194  LoggingLevel LogManager::getLogDetail()
00195  {
00196   if (mDefaultLog)
00197   {
00198    return mDefaultLog->getLogDetail();
00199   }
00200   return LL_Low;
00201  }
00202 }

Generated on Thu Mar 5 22:36:42 2009 for gpucalc by  doxygen 1.5.6