1 | /************************************************************************
|
---|
2 | filename: CEGUILogger.h
|
---|
3 | created: 21/2/2004
|
---|
4 | author: Paul D Turner
|
---|
5 |
|
---|
6 | purpose: Defines interface for the Logger class
|
---|
7 | *************************************************************************/
|
---|
8 | /*************************************************************************
|
---|
9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
11 |
|
---|
12 | This library is free software; you can redistribute it and/or
|
---|
13 | modify it under the terms of the GNU Lesser General Public
|
---|
14 | License as published by the Free Software Foundation; either
|
---|
15 | version 2.1 of the License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This library is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | Lesser General Public License for more details.
|
---|
21 |
|
---|
22 | You should have received a copy of the GNU Lesser General Public
|
---|
23 | License along with this library; if not, write to the Free Software
|
---|
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | *************************************************************************/
|
---|
26 | #ifndef _CEGUILogger_h_
|
---|
27 | #define _CEGUILogger_h_
|
---|
28 |
|
---|
29 | #include "CEGUIBase.h"
|
---|
30 | #include "CEGUIString.h"
|
---|
31 | #include <fstream>
|
---|
32 | #include <sstream>
|
---|
33 | #include <vector>
|
---|
34 | #include <utility>
|
---|
35 | #include "CEGUISingleton.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | #if defined(_MSC_VER)
|
---|
39 | # pragma warning(push)
|
---|
40 | # pragma warning(disable : 4275)
|
---|
41 | # pragma warning(disable : 4251)
|
---|
42 | #endif
|
---|
43 |
|
---|
44 |
|
---|
45 | // Start of CEGUI namespace section
|
---|
46 | namespace CEGUI
|
---|
47 | {
|
---|
48 |
|
---|
49 | /*!
|
---|
50 | \brief
|
---|
51 | Enumeration of logging levels
|
---|
52 | */
|
---|
53 | enum LoggingLevel
|
---|
54 | {
|
---|
55 | Errors, //!< Only actual error conditions will be logged.
|
---|
56 | Standard, //!< Basic events will be logged (default level).
|
---|
57 | Informative, //!< Useful tracing (object creations etc) information will be logged.
|
---|
58 | Insane //!< Mostly everything gets logged (use for heavy tracing only, log WILL be big).
|
---|
59 | };
|
---|
60 |
|
---|
61 | /*!
|
---|
62 | \brief
|
---|
63 | Class that implements logging for the GUI system
|
---|
64 | */
|
---|
65 | class CEGUIEXPORT Logger : public Singleton <Logger>
|
---|
66 | {
|
---|
67 | public:
|
---|
68 | /*!
|
---|
69 | \brief
|
---|
70 | Constructor for Logger object.
|
---|
71 | */
|
---|
72 | Logger(void);
|
---|
73 |
|
---|
74 | /*!
|
---|
75 | \brief Destructor for Logger object.
|
---|
76 | */
|
---|
77 | ~Logger(void);
|
---|
78 |
|
---|
79 |
|
---|
80 | /*!
|
---|
81 | \brief
|
---|
82 | Return the singleton Logger object
|
---|
83 |
|
---|
84 | \return
|
---|
85 | Reference to the one and only Logger object
|
---|
86 | */
|
---|
87 | static Logger& getSingleton(void);
|
---|
88 |
|
---|
89 |
|
---|
90 | /*!
|
---|
91 | \brief
|
---|
92 | Set the level of logging information that will get out to the log file
|
---|
93 |
|
---|
94 | \param level
|
---|
95 | One of the LoggingLevel enumerated values that specified the level of logging information required.
|
---|
96 |
|
---|
97 | \return
|
---|
98 | Nothing
|
---|
99 | */
|
---|
100 | void setLoggingLevel(LoggingLevel level) {d_level = level;}
|
---|
101 |
|
---|
102 |
|
---|
103 | /*!
|
---|
104 | \brief
|
---|
105 | return the current logging level setting
|
---|
106 |
|
---|
107 | \return
|
---|
108 | One of the LoggingLevel enumerated values specifying the current level of logging
|
---|
109 | */
|
---|
110 | LoggingLevel getLoggingLevel(void) const {return d_level;}
|
---|
111 |
|
---|
112 |
|
---|
113 | /*!
|
---|
114 | \brief
|
---|
115 | Add an event to the log.
|
---|
116 |
|
---|
117 | \param message
|
---|
118 | String object containing the message to be added to the event log.
|
---|
119 |
|
---|
120 | \param level
|
---|
121 | LoggingLevel for this message. If \a level is greater than the current set logging level, the message is not logged.
|
---|
122 |
|
---|
123 | \return
|
---|
124 | Nothing
|
---|
125 | */
|
---|
126 | void logEvent(const String& message, LoggingLevel level = Standard);
|
---|
127 |
|
---|
128 | /*!
|
---|
129 | \brief
|
---|
130 | Set the name of the log file where all subsequent log entries should be written.
|
---|
131 |
|
---|
132 | \note
|
---|
133 | When this is called, and the log file is created, any cached log entries are
|
---|
134 | flushed to the log file.
|
---|
135 |
|
---|
136 | \param filename
|
---|
137 | Name of the file to put log messages.
|
---|
138 |
|
---|
139 | \param append
|
---|
140 | - true if events should be added to the end of the current file.
|
---|
141 | - false if the current contents of the file should be discarded.
|
---|
142 | */
|
---|
143 | void setLogFilename(const String& filename, bool append = false);
|
---|
144 |
|
---|
145 | protected:
|
---|
146 | /*************************************************************************
|
---|
147 | Implementation Data
|
---|
148 | *************************************************************************/
|
---|
149 | LoggingLevel d_level; //!< Holds current logging level
|
---|
150 | std::ofstream d_ostream; //!< Stream used to implement the logger
|
---|
151 | std::vector<std::pair<String, LoggingLevel> > d_cache; //!< Used to cache log entries before log file is created.
|
---|
152 | std::ostringstream d_workstream;//!< Used to build log entry strings.
|
---|
153 | bool d_caching; //!< true while log entries are beign cached (prior to logfile creation)
|
---|
154 |
|
---|
155 | private:
|
---|
156 | /*************************************************************************
|
---|
157 | Copy constructor and assignment usage is denied.
|
---|
158 | *************************************************************************/
|
---|
159 | Logger(const Logger& logger) {}
|
---|
160 | Logger& operator=(const Logger& logger) {return *this;}
|
---|
161 |
|
---|
162 | };
|
---|
163 |
|
---|
164 | /*************************************************************************
|
---|
165 | This macro is used for 'Insane' level logging so that those items are
|
---|
166 | excluded from non-debug builds
|
---|
167 | *************************************************************************/
|
---|
168 | #if defined(DEBUG) || defined (_DEBUG)
|
---|
169 | # define CEGUI_LOGINSANE( message ) CEGUI::Logger::getSingleton().logEvent((message), CEGUI::Insane);
|
---|
170 | #else
|
---|
171 | # define CEGUI_LOGINSANE( message )
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | } // End of CEGUI namespace section
|
---|
175 |
|
---|
176 | #if defined(_MSC_VER)
|
---|
177 | # pragma warning(pop)
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | #endif // end of guard _CEGUILogger_h_
|
---|