PCMLogger.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 #ifndef __PCM_LOGGER_H__
00029 #  define __PCM_LOGGER_H__
00030 
00031 //
00032 // Inner includes
00033 //
00034 
00035 #  include "PCMPremeditations.h"
00036 
00037 #  include "PCMSingleton.h"
00038 
00039 #  include "PCMPointer.h"
00040 
00041 #  include "PCMException.h"
00042 
00043 #  include "PCMTimer.h"
00044 
00045 //
00046 // Outer includes
00047 //
00048 
00049 #  include <string>
00050 
00051 #  include <sstream>
00052 
00053 namespace ParCompMark
00054 {
00055 
00060   class Logger:public Singleton < Logger >
00061   {
00062 
00063         //
00064         // Unit test class
00065         //
00066 #  ifdef PARCOMPMARK_TEST
00067         friend class ParCompMarkTest::TestLogger;
00068 #  endif
00069 
00070         //
00071         // Enumerations
00072         //
00073 
00074    public:
00075 
00077         enum LogLevel
00078         {
00079 
00081          FATAL,
00082 
00084          ERROR,
00085 
00087          WARNING,
00088 
00090          NOTICE,
00091 
00093          DEBUG
00094         };
00095 
00096         //
00097         // Class constants
00098         //
00099 
00101 
00102 
00103    public:
00104 
00110         static const u8 LOGTOCONSOLE;
00111 
00117         static const u8 LOGTOFILE;
00118 
00120 
00121         //
00122         // Variables
00123         //
00124 
00126 
00127 
00128    protected:
00129 
00135         u8 mLogMode;
00136 
00142         LogLevel mConsoleLogLevel;
00143 
00149         LogLevel mFileLogLevel;
00150 
00156         Pointer < FILE, Mutex > mFp;
00157 
00163         bool mInitialized;
00164 
00170         std::string mLogFileName;
00171 
00173 
00174         //
00175         // Constructors & destructor
00176         //
00177 
00179 
00180 
00181    public:
00182 
00187         Logger(const std::string & logFileName = "parcompmark.log");
00188 
00192         virtual ~ Logger();
00193 
00195 
00196         //
00197         // Getters & setters
00198         //
00199 
00201 
00202 
00203    public:
00204 
00210         const u8 & getLogMode() const;
00211 
00217         const Logger::LogLevel & getConsoleLogLevel() const;
00218 
00224         void setConsoleLogLevel(const Logger::LogLevel & consoleloglevel);
00225 
00231         const Logger::LogLevel & getFileLogLevel() const;
00232 
00238         void setFileLogLevel(const Logger::LogLevel & fileloglevel);
00239 
00245         const bool & getInitialized() const;
00246 
00252         const std::string & getLogFileName() const;
00253 
00259         void setLogFileName(const std::string & logfilename);
00260 
00262 
00263         //
00264         // Class methods
00265         //
00266 
00268 
00269 
00270    public:
00271 
00277         static std::string translateLogLevel(const LogLevel & loglevel);
00278 
00284         static std::string translateException(const Exception & exception);
00285 
00287 
00288         //
00289         // Methods
00290         //
00291 
00293 
00294 
00295    public:
00296 
00300         virtual void initialize();
00301 
00307         virtual void log(const LogLevel & loglevel, const std::string & message);
00308 
00314         virtual void logMultiLine(const LogLevel & loglevel, const std::string & message);
00315 
00320         virtual void log(const Exception & exception);
00321 
00323 
00324   };
00325 
00326   //
00327   // Include header implementation
00328   //
00329 
00330 #  include "PCMLogger_impl.h"
00331 
00332 }
00333 
00334 #endif