1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef __LogManager_H__
|
---|
27 | #define __LogManager_H__
|
---|
28 |
|
---|
29 | #include "OgrePrerequisites.h"
|
---|
30 |
|
---|
31 | #include "OgreLog.h"
|
---|
32 | #include "OgreSingleton.h"
|
---|
33 | #include "OgreString.h"
|
---|
34 |
|
---|
35 | namespace Ogre {
|
---|
36 |
|
---|
37 | /** The log listener is here to provide alternate means to write out
|
---|
38 | log data. This is helpful if you want to redirect the log output
|
---|
39 | for example to a gui window for an editing application.
|
---|
40 | */
|
---|
41 | class _OgreExport LogListener
|
---|
42 | {
|
---|
43 | public:
|
---|
44 | /** Called by the log system whenever a message needs to be output.
|
---|
45 | */
|
---|
46 | virtual void write( const String& name,
|
---|
47 | const String& message,
|
---|
48 | LogMessageLevel lml = LML_NORMAL,
|
---|
49 | bool maskDebug = false ) = 0;
|
---|
50 | virtual ~LogListener();
|
---|
51 | };
|
---|
52 |
|
---|
53 | /** The log manager handles the creation and retrieval of logs for the
|
---|
54 | application.
|
---|
55 | @remarks
|
---|
56 | This class will create new log files and will retrieve instances
|
---|
57 | of existing ones. Other classes wishing to log output can either
|
---|
58 | create a fresh log or retrieve an existing one to output to.
|
---|
59 | One log is the default log, and is the one written to when the
|
---|
60 | logging methods of this class are called.
|
---|
61 | */
|
---|
62 | class _OgreExport LogManager : public Singleton<LogManager>
|
---|
63 | {
|
---|
64 | friend class Log;
|
---|
65 |
|
---|
66 | protected:
|
---|
67 |
|
---|
68 | /** Internal helper method to reroute logging messages to the
|
---|
69 | new listener system, while maintaining full backward compatiblity.
|
---|
70 | */
|
---|
71 | void _routeMessage( const String& name,
|
---|
72 | const String& message,
|
---|
73 | LogMessageLevel lml = LML_NORMAL,
|
---|
74 | bool maskDebug = false );
|
---|
75 |
|
---|
76 | typedef std::map<String, Log*, std::less<String> > LogList;
|
---|
77 | typedef std::vector<LogListener*> LogListenerList;
|
---|
78 |
|
---|
79 | /// A list of all the logs the manager can access
|
---|
80 | LogList mLogs;
|
---|
81 |
|
---|
82 | /// The default log to which output is done
|
---|
83 | Log* mDefaultLog;
|
---|
84 |
|
---|
85 | /// A list of all registered external log listeners.
|
---|
86 | LogListenerList mListeners;
|
---|
87 |
|
---|
88 | public:
|
---|
89 | LogManager();
|
---|
90 | ~LogManager();
|
---|
91 |
|
---|
92 | /** Adds a new listener for the logging system.
|
---|
93 | Ogre does not assume ownership and does not destroy the listener
|
---|
94 | at application shutdown.
|
---|
95 | */
|
---|
96 | void addListener( LogListener * listener );
|
---|
97 |
|
---|
98 | /** Removes a previously registered listener again, and
|
---|
99 | returns ownership of the listener to the caller, who
|
---|
100 | is responsible for destroying the listener again.
|
---|
101 | */
|
---|
102 | void removeListener( LogListener * listener );
|
---|
103 |
|
---|
104 | /** Creates a new log with the given name.
|
---|
105 | @param
|
---|
106 | name The name to give the log e.g. 'Ogre.log'
|
---|
107 | @param
|
---|
108 | defaultLog If true, this is the default log output will be
|
---|
109 | sent to if the generic logging methods on this class are
|
---|
110 | used. The first log created is always the default log unless
|
---|
111 | this parameter is set.
|
---|
112 | @param
|
---|
113 | debuggerOutput If true, output to this log will also be
|
---|
114 | routed to the debugger's output window.
|
---|
115 | @param
|
---|
116 | suppressFileOutput If true, this is a logical rather than a physical
|
---|
117 | log and no file output will be written. If you do this you should
|
---|
118 | register a LogListener so log output is not lost.
|
---|
119 | */
|
---|
120 | Log* createLog( const String& name, bool defaultLog = false, bool debuggerOutput = true,
|
---|
121 | bool suppressFileOutput = false);
|
---|
122 |
|
---|
123 | /** Retrieves a log managed by this class.
|
---|
124 | */
|
---|
125 | Log* getLog( const String& name);
|
---|
126 |
|
---|
127 | /** Returns a pointer to the default log.
|
---|
128 | */
|
---|
129 | Log* getDefaultLog();
|
---|
130 |
|
---|
131 | /** Sets the passed in log as the default log.
|
---|
132 | @returns The previous default log.
|
---|
133 | */
|
---|
134 | Log* setDefaultLog(Log* newLog);
|
---|
135 |
|
---|
136 | /** Log a message to the default log.
|
---|
137 | */
|
---|
138 | void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL,
|
---|
139 | bool maskDebug = false);
|
---|
140 |
|
---|
141 | /** Log a message to the default log (signature for backward compatibility).
|
---|
142 | */
|
---|
143 | void logMessage( LogMessageLevel lml, const String& message,
|
---|
144 | bool maskDebug = false) { logMessage(message, lml, maskDebug); }
|
---|
145 |
|
---|
146 | /** Sets the level of detail of the default log.
|
---|
147 | */
|
---|
148 | void setLogDetail(LoggingLevel ll);
|
---|
149 | /** Override standard Singleton retrieval.
|
---|
150 | @remarks
|
---|
151 | Why do we do this? Well, it's because the Singleton
|
---|
152 | implementation is in a .h file, which means it gets compiled
|
---|
153 | into anybody who includes it. This is needed for the
|
---|
154 | Singleton template to work, but we actually only want it
|
---|
155 | compiled into the implementation of the class based on the
|
---|
156 | Singleton, not all of them. If we don't change this, we get
|
---|
157 | link errors when trying to use the Singleton-based class from
|
---|
158 | an outside dll.
|
---|
159 | @par
|
---|
160 | This method just delegates to the template version anyway,
|
---|
161 | but the implementation stays in this single compilation unit,
|
---|
162 | preventing link errors.
|
---|
163 | */
|
---|
164 | static LogManager& getSingleton(void);
|
---|
165 | /** Override standard Singleton retrieval.
|
---|
166 | @remarks
|
---|
167 | Why do we do this? Well, it's because the Singleton
|
---|
168 | implementation is in a .h file, which means it gets compiled
|
---|
169 | into anybody who includes it. This is needed for the
|
---|
170 | Singleton template to work, but we actually only want it
|
---|
171 | compiled into the implementation of the class based on the
|
---|
172 | Singleton, not all of them. If we don't change this, we get
|
---|
173 | link errors when trying to use the Singleton-based class from
|
---|
174 | an outside dll.
|
---|
175 | @par
|
---|
176 | This method just delegates to the template version anyway,
|
---|
177 | but the implementation stays in this single compilation unit,
|
---|
178 | preventing link errors.
|
---|
179 | */
|
---|
180 | static LogManager* getSingletonPtr(void);
|
---|
181 |
|
---|
182 | };
|
---|
183 |
|
---|
184 | }
|
---|
185 |
|
---|
186 | #endif
|
---|