# CEGUILogger.h

    00001 /************************************************************************
    00002         filename:       CEGUILogger.h
    00003         created:        21/2/2004
    00004         author:         Paul D Turner
    00005
    00006         purpose:        Defines interface for the Logger class
    00007 *************************************************************************/
    00008 /*************************************************************************
    00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
    00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
    00011
    00012     This library is free software; you can redistribute it and/or
    00013     modify it under the terms of the GNU Lesser General Public
    00014     License as published by the Free Software Foundation; either
    00015     version 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 GNU
    00020     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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00025 *************************************************************************/
    00026 #ifndef _CEGUILogger_h_
    00027 #define _CEGUILogger_h_
    00028
    00029 #include "CEGUIBase.h"
    00030 #include "CEGUIString.h"
    00031 #include <fstream>
    00032 #include <sstream>
    00033 #include <vector>
    00034 #include <utility>
    00035 #include "CEGUISingleton.h"
    00036
    00037
    00038 #if defined(_MSC_VER)
    00039 #       pragma warning(push)
    00040 #       pragma warning(disable : 4275)
    00041 #       pragma warning(disable : 4251)
    00042 #endif
    00043
    00044
    00045 // Start of CEGUI namespace section
    00046 namespace CEGUI
    00047 {
    00048
    00053 enum LoggingLevel
    00054 {
    00055         Errors,
    00056         Standard,
    00057         Informative,
    00058         Insane
    00059 };
    00060
    00065 class CEGUIEXPORT Logger : public Singleton <Logger>
    00066 {
    00067 public:
    00072         Logger(void);
    00073
    00077         ~Logger(void);
    00078
    00079
    00087         static Logger&  getSingleton(void);
    00088
    00089
    00100         void    setLoggingLevel(LoggingLevel level)             {d_level = level;}
    00101
    00102
    00110         LoggingLevel    getLoggingLevel(void) const             {return d_level;}
    00111
    00112
    00126         void    logEvent(const String& message, LoggingLevel level = Standard);
    00127
    00143     void    setLogFilename(const String& filename, bool append = false);
    00144
    00145 protected:
    00146     /*************************************************************************
    00147                 Implementation Data
    00148         *************************************************************************/
    00149         LoggingLevel    d_level;
    00150         std::ofstream   d_ostream;
    00151     std::vector<std::pair<String, LoggingLevel> > d_cache;
    00152     std::ostringstream d_workstream;
    00153     bool d_caching;
    00154
    00155 private:
    00156         /*************************************************************************
    00157                 Copy constructor and assignment usage is denied.
    00158         *************************************************************************/
    00159         Logger(const Logger& logger) {}
    00160         Logger& operator=(const Logger& logger) {return *this;}
    00161
    00162 };
    00163
    00164 /*************************************************************************
    00165         This macro is used for 'Insane' level logging so that those items are
    00166         excluded from non-debug builds
    00167 *************************************************************************/
    00168 #if defined(DEBUG) || defined (_DEBUG)
    00169 #       define CEGUI_LOGINSANE( message ) CEGUI::Logger::getSingleton().logEvent((message), CEGUI::Insane);
    00170 #else
    00171 #       define CEGUI_LOGINSANE( message )
    00172 #endif
    00173
    00174 } // End of  CEGUI namespace section
    00175
    00176 #if defined(_MSC_VER)
    00177 #       pragma warning(pop)
    00178 #endif
    00179
    00180 #endif  // end of guard _CEGUILogger_h_