[148] | 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-2013 Torus Knot Software Ltd |
---|
| 8 | |
---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
---|
| 11 | in the Software without restriction, including without limitation the rights |
---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
---|
| 14 | furnished to do so, subject to the following conditions: |
---|
| 15 | |
---|
| 16 | The above copyright notice and this permission notice shall be included in |
---|
| 17 | all copies or substantial portions of the Software. |
---|
| 18 | |
---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 25 | THE SOFTWARE. |
---|
| 26 | ----------------------------------------------------------------------------- |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef __LogManager_H__ |
---|
| 30 | #define __LogManager_H__ |
---|
| 31 | |
---|
| 32 | #include "OgrePrerequisites.h" |
---|
| 33 | |
---|
| 34 | #include "OgreLog.h" |
---|
| 35 | #include "OgreSingleton.h" |
---|
| 36 | #include "OgreString.h" |
---|
| 37 | #include "OgreHeaderPrefix.h" |
---|
| 38 | |
---|
| 39 | namespace Ogre |
---|
| 40 | { |
---|
| 41 | /** \addtogroup Core |
---|
| 42 | * @{ |
---|
| 43 | */ |
---|
| 44 | /** \addtogroup General |
---|
| 45 | * @{ |
---|
| 46 | */ |
---|
| 47 | /** The log manager handles the creation and retrieval of logs for the |
---|
| 48 | application. |
---|
| 49 | @remarks |
---|
| 50 | This class will create new log files and will retrieve instances |
---|
| 51 | of existing ones. Other classes wishing to log output can either |
---|
| 52 | create a fresh log or retrieve an existing one to output to. |
---|
| 53 | One log is the default log, and is the one written to when the |
---|
| 54 | logging methods of this class are called. |
---|
| 55 | @par |
---|
| 56 | By default, Root will instantiate a LogManager (which becomes the |
---|
| 57 | Singleton instance) on construction, and will create a default log |
---|
| 58 | based on the Root construction parameters. If you want more control, |
---|
| 59 | for example redirecting log output right from the start or suppressing |
---|
| 60 | debug output, you need to create a LogManager yourself before creating |
---|
| 61 | a Root instance, then create a default log. Root will detect that |
---|
| 62 | you've created one yourself and won't create one of its own, thus |
---|
| 63 | using all your logging preferences from the first instance. |
---|
| 64 | */ |
---|
| 65 | class _OgreExport LogManager : public Singleton<LogManager>, public LogAlloc |
---|
| 66 | { |
---|
| 67 | protected: |
---|
| 68 | typedef map<String, Log*>::type LogList; |
---|
| 69 | |
---|
| 70 | /// A list of all the logs the manager can access |
---|
| 71 | LogList mLogs; |
---|
| 72 | |
---|
| 73 | /// The default log to which output is done |
---|
| 74 | Log* mDefaultLog; |
---|
| 75 | |
---|
| 76 | public: |
---|
| 77 | OGRE_AUTO_MUTEX; // public to allow external locking |
---|
| 78 | |
---|
| 79 | LogManager(); |
---|
| 80 | ~LogManager(); |
---|
| 81 | |
---|
| 82 | /** Creates a new log with the given name. |
---|
| 83 | @param |
---|
| 84 | name The name to give the log e.g. 'Ogre.log' |
---|
| 85 | @param |
---|
| 86 | defaultLog If true, this is the default log output will be |
---|
| 87 | sent to if the generic logging methods on this class are |
---|
| 88 | used. The first log created is always the default log unless |
---|
| 89 | this parameter is set. |
---|
| 90 | @param |
---|
| 91 | debuggerOutput If true, output to this log will also be |
---|
| 92 | routed to the debugger's output window. |
---|
| 93 | @param |
---|
| 94 | suppressFileOutput If true, this is a logical rather than a physical |
---|
| 95 | log and no file output will be written. If you do this you should |
---|
| 96 | register a LogListener so log output is not lost. |
---|
| 97 | */ |
---|
| 98 | Log* createLog( const String& name, bool defaultLog = false, bool debuggerOutput = true, |
---|
| 99 | bool suppressFileOutput = false); |
---|
| 100 | |
---|
| 101 | /** Retrieves a log managed by this class. |
---|
| 102 | */ |
---|
| 103 | Log* getLog( const String& name); |
---|
| 104 | |
---|
| 105 | /** Returns a pointer to the default log. |
---|
| 106 | */ |
---|
| 107 | Log* getDefaultLog(); |
---|
| 108 | |
---|
| 109 | /** Closes and removes a named log. */ |
---|
| 110 | void destroyLog(const String& name); |
---|
| 111 | /** Closes and removes a log. */ |
---|
| 112 | void destroyLog(Log* log); |
---|
| 113 | |
---|
| 114 | /** Sets the passed in log as the default log. |
---|
| 115 | @return The previous default log. |
---|
| 116 | */ |
---|
| 117 | Log* setDefaultLog(Log* newLog); |
---|
| 118 | |
---|
| 119 | /** Log a message to the default log. |
---|
| 120 | */ |
---|
| 121 | void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, |
---|
| 122 | bool maskDebug = false); |
---|
| 123 | |
---|
| 124 | /** Log a message to the default log (signature for backward compatibility). |
---|
| 125 | */ |
---|
| 126 | void logMessage( LogMessageLevel lml, const String& message, |
---|
| 127 | bool maskDebug = false) { logMessage(message, lml, maskDebug); } |
---|
| 128 | |
---|
| 129 | /** Get a stream on the default log. */ |
---|
| 130 | Log::Stream stream(LogMessageLevel lml = LML_NORMAL, |
---|
| 131 | bool maskDebug = false); |
---|
| 132 | |
---|
| 133 | /** Sets the level of detail of the default log. |
---|
| 134 | */ |
---|
| 135 | void setLogDetail(LoggingLevel ll); |
---|
| 136 | /** Override standard Singleton retrieval. |
---|
| 137 | @remarks |
---|
| 138 | Why do we do this? Well, it's because the Singleton |
---|
| 139 | implementation is in a .h file, which means it gets compiled |
---|
| 140 | into anybody who includes it. This is needed for the |
---|
| 141 | Singleton template to work, but we actually only want it |
---|
| 142 | compiled into the implementation of the class based on the |
---|
| 143 | Singleton, not all of them. If we don't change this, we get |
---|
| 144 | link errors when trying to use the Singleton-based class from |
---|
| 145 | an outside dll. |
---|
| 146 | @par |
---|
| 147 | This method just delegates to the template version anyway, |
---|
| 148 | but the implementation stays in this single compilation unit, |
---|
| 149 | preventing link errors. |
---|
| 150 | */ |
---|
| 151 | static LogManager& getSingleton(void); |
---|
| 152 | /** Override standard Singleton retrieval. |
---|
| 153 | @remarks |
---|
| 154 | Why do we do this? Well, it's because the Singleton |
---|
| 155 | implementation is in a .h file, which means it gets compiled |
---|
| 156 | into anybody who includes it. This is needed for the |
---|
| 157 | Singleton template to work, but we actually only want it |
---|
| 158 | compiled into the implementation of the class based on the |
---|
| 159 | Singleton, not all of them. If we don't change this, we get |
---|
| 160 | link errors when trying to use the Singleton-based class from |
---|
| 161 | an outside dll. |
---|
| 162 | @par |
---|
| 163 | This method just delegates to the template version anyway, |
---|
| 164 | but the implementation stays in this single compilation unit, |
---|
| 165 | preventing link errors. |
---|
| 166 | */ |
---|
| 167 | static LogManager* getSingletonPtr(void); |
---|
| 168 | |
---|
| 169 | }; |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | /** @} */ |
---|
| 173 | /** @} */ |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | #include "OgreHeaderSuffix.h" |
---|
| 177 | |
---|
| 178 | #endif |
---|