source: GTP/trunk/Lib/Geom/OgreStuff/include/OgreLogManager.h @ 1809

Revision 1809, 7.5 KB checked in by gumbau, 18 years ago (diff)
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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
35namespace 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                @par
62                        By default, Root will instantiate a LogManager (which becomes the
63                        Singleton instance) on construction, and will create a default log
64                        based on the Root construction parameters. If you want more control,
65                        for example redirecting log output right from the start or suppressing
66                        debug output, you need to create a LogManager yourself before creating
67                        a Root instance, then create a default log. Root will detect that
68                        you've created one yourself and won't create one of its own, thus
69                        using all your logging preferences from the first instance.
70    */
71    class _OgreExport LogManager : public Singleton<LogManager>
72    {
73                friend class Log;
74
75        protected:
76
77                /** Internal helper method to reroute logging messages to the
78                        new listener system, while maintaining full backward compatiblity.
79                */
80                void _routeMessage(     const String& name,
81                                                        const String& message,
82                                                        LogMessageLevel lml = LML_NORMAL,
83                                                        bool maskDebug = false );
84
85        typedef std::map<String, Log*, std::less<String> >      LogList;
86                typedef std::vector<LogListener*>                                       LogListenerList;
87
88        /// A list of all the logs the manager can access
89        LogList mLogs;
90
91        /// The default log to which output is done
92        Log* mDefaultLog;
93
94                /// A list of all registered external log listeners.
95                LogListenerList mListeners;
96
97    public:
98        LogManager();
99        ~LogManager();
100
101                /** Adds a new listener for the logging system.
102                    Ogre does not assume ownership and does not destroy the listener
103                        at application shutdown.
104                */
105                void addListener( LogListener * listener );
106               
107                /** Removes a previously registered listener again, and
108                        returns ownership of the listener to the caller, who
109                        is responsible for destroying the listener again.
110                */
111                void removeListener( LogListener * listener );
112
113        /** Creates a new log with the given name.
114            @param
115                name The name to give the log e.g. 'Ogre.log'
116            @param
117                defaultLog If true, this is the default log output will be
118                sent to if the generic logging methods on this class are
119                used. The first log created is always the default log unless
120                this parameter is set.
121            @param
122                debuggerOutput If true, output to this log will also be
123                routed to the debugger's output window.
124            @param
125                suppressFileOutput If true, this is a logical rather than a physical
126                                log and no file output will be written. If you do this you should
127                                register a LogListener so log output is not lost.
128        */
129        Log* createLog( const String& name, bool defaultLog = false, bool debuggerOutput = true,
130                        bool suppressFileOutput = false);
131
132        /** Retrieves a log managed by this class.
133        */
134        Log* getLog( const String& name);
135
136        /** Returns a pointer to the default log.
137        */
138        Log* getDefaultLog();
139
140        /** Sets the passed in log as the default log.
141        @returns The previous default log.
142        */
143        Log* setDefaultLog(Log* newLog);
144
145        /** Log a message to the default log.
146        */
147        void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL,
148            bool maskDebug = false);
149
150        /** Log a message to the default log (signature for backward compatibility).
151        */
152        void logMessage( LogMessageLevel lml, const String& message, 
153                        bool maskDebug = false) { logMessage(message, lml, maskDebug); }
154
155                /** Sets the level of detail of the default log.
156        */
157        void setLogDetail(LoggingLevel ll);
158        /** Override standard Singleton retrieval.
159        @remarks
160        Why do we do this? Well, it's because the Singleton
161        implementation is in a .h file, which means it gets compiled
162        into anybody who includes it. This is needed for the
163        Singleton template to work, but we actually only want it
164        compiled into the implementation of the class based on the
165        Singleton, not all of them. If we don't change this, we get
166        link errors when trying to use the Singleton-based class from
167        an outside dll.
168        @par
169        This method just delegates to the template version anyway,
170        but the implementation stays in this single compilation unit,
171        preventing link errors.
172        */
173        static LogManager& getSingleton(void);
174        /** Override standard Singleton retrieval.
175        @remarks
176        Why do we do this? Well, it's because the Singleton
177        implementation is in a .h file, which means it gets compiled
178        into anybody who includes it. This is needed for the
179        Singleton template to work, but we actually only want it
180        compiled into the implementation of the class based on the
181        Singleton, not all of them. If we don't change this, we get
182        link errors when trying to use the Singleton-based class from
183        an outside dll.
184        @par
185        This method just delegates to the template version anyway,
186        but the implementation stays in this single compilation unit,
187        preventing link errors.
188        */
189        static LogManager* getSingletonPtr(void);
190
191    };
192
193}
194
195#endif
Note: See TracBrowser for help on using the repository browser.