PCMLogger_impl.h

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00027 
00028  //
00029  // Getters & setters
00030  //
00031 
00032 inline const u8 & Logger::getLogMode() const
00033 {
00034   return mLogMode;
00035 }
00036 
00037  /*-------------------------------------------------------------------------*/
00038 
00039 inline const Logger::LogLevel & Logger::getConsoleLogLevel() const
00040 {
00041   return mConsoleLogLevel;
00042 }
00043 
00044  /*-------------------------------------------------------------------------*/
00045 
00046 inline void Logger::setConsoleLogLevel(const Logger::LogLevel & consoleloglevel)
00047 {
00048   mConsoleLogLevel = consoleloglevel;
00049 }
00050 
00051  /*-------------------------------------------------------------------------*/
00052 
00053 inline const Logger::LogLevel & Logger::getFileLogLevel() const
00054 {
00055   return mFileLogLevel;
00056 }
00057 
00058  /*-------------------------------------------------------------------------*/
00059 
00060 inline void Logger::setFileLogLevel(const Logger::LogLevel & fileloglevel)
00061 {
00062   mFileLogLevel = fileloglevel;
00063 }
00064 
00065  /*-------------------------------------------------------------------------*/
00066 
00067 inline const bool & Logger::getInitialized() const
00068 {
00069   return mInitialized;
00070 }
00071 
00072  /*-------------------------------------------------------------------------*/
00073 
00074 inline const std::string & Logger::getLogFileName() const
00075 {
00076   return mLogFileName;
00077 }
00078 
00079  /*-------------------------------------------------------------------------*/
00080 
00081 inline void Logger::setLogFileName(const std::string & logfilename)
00082 {
00083   mLogFileName = logfilename;
00084 }
00085 
00086  /*-------------------------------------------------------------------------*/
00087 
00088  //
00089  // Class methods
00090  //
00091 
00092 inline std::string Logger::translateLogLevel(const LogLevel & loglevel)
00093 {
00094 
00095   switch (loglevel)
00096   {
00097         case Logger::FATAL:
00098          return "[FATAL]----:";
00099          break;
00100         case Logger::ERROR:
00101          return "[ERROR]----:";
00102          break;
00103         case Logger::WARNING:
00104          return "[WARNING]--:";
00105          break;
00106         case Logger::NOTICE:
00107          return "[NOTICE]---:";
00108          break;
00109         case Logger::DEBUG:
00110          return "[DEBUG]----:";
00111          break;
00112   }
00113 
00114   return "[unknown]--:";
00115 
00116 }
00117 
00118  /*----------------------------------------------------------------------*/
00119 
00120  //
00121  // Methods
00122  //
00123 
00124 inline void Logger::log(const LogLevel & loglevel, const std::string & message)
00125 {
00126   Assert(mInitialized, NULL_POINTER_ERROR, "Logger::log()");
00127   // File pointer locks the console too
00128 
00129   mFp.lock();
00130 
00131   // Log to console
00132   if(mLogMode & LOGTOCONSOLE)
00133   {
00134         if(loglevel <= mConsoleLogLevel)
00135         {
00136 
00137          if(loglevel > ERROR)
00138                 std::cout << "PCM: " << translateLogLevel(loglevel) << " " << message << std::endl;
00139          else
00140                 std::cerr << "PCM: " << translateLogLevel(loglevel) << " " << message << std::endl;
00141         }
00142   }
00143   // Log to file
00144   if(mLogMode & LOGTOFILE)
00145   {
00146         if(loglevel <= mFileLogLevel)
00147         {
00148          fprintf(mFp.getPtr(), "[%s] %s %s\n", Timer::getTimeString().c_str(), translateLogLevel(loglevel).c_str(),
00149                  message.c_str());
00150 
00151          // Flush the buffer
00152          fflush(mFp.getPtr());
00153         }
00154   }
00155 
00156   mFp.unlock();
00157 
00158 }
00159 
00160  /*----------------------------------------------------------------------*/
00161 
00162 inline void Logger::log(const Exception & exception)
00163 {
00164   Assert(mInitialized, NULL_POINTER_ERROR, "Logger::log()");
00165 
00166   log(FATAL, translateException(exception));
00167 }
00168 
00169  /*----------------------------------------------------------------------*/