[1] | 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-2006 Torus Knot Software Ltd |
---|
| 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 | You may alternatively use this source under the terms of a specific version of |
---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
| 26 | Torus Knot Software Ltd. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef __Log_H__ |
---|
| 31 | #define __Log_H__ |
---|
| 32 | |
---|
| 33 | #include "OgrePrerequisites.h" |
---|
| 34 | |
---|
| 35 | namespace Ogre { |
---|
| 36 | |
---|
| 37 | // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged |
---|
| 38 | #define OGRE_LOG_THRESHOLD 4 |
---|
| 39 | |
---|
| 40 | /** The level of detail to which the log will go into. |
---|
| 41 | */ |
---|
| 42 | enum LoggingLevel |
---|
| 43 | { |
---|
| 44 | LL_LOW = 1, |
---|
| 45 | LL_NORMAL = 2, |
---|
| 46 | LL_BOREME = 3 |
---|
| 47 | }; |
---|
| 48 | |
---|
| 49 | /** The importance of a logged message. |
---|
| 50 | */ |
---|
| 51 | enum LogMessageLevel |
---|
| 52 | { |
---|
| 53 | LML_TRIVIAL = 1, |
---|
| 54 | LML_NORMAL = 2, |
---|
| 55 | LML_CRITICAL = 3 |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | /** @remarks Pure Abstract class, derive this class and register to the Log to listen to log messages */ |
---|
| 59 | class LogListener |
---|
| 60 | { |
---|
| 61 | public: |
---|
| 62 | virtual ~LogListener() {}; |
---|
| 63 | |
---|
| 64 | /** |
---|
| 65 | @remarks |
---|
| 66 | This is called whenever the log recieves a message and is about to write it out |
---|
| 67 | @param message |
---|
| 68 | The message to be logged |
---|
| 69 | @param lml |
---|
| 70 | The message level the log is using |
---|
| 71 | @param maskDebug |
---|
| 72 | If we are printing to the console or not |
---|
| 73 | @param logName |
---|
| 74 | the name of this log (so you can have several listeners for different logs, and identify them) |
---|
| 75 | */ |
---|
| 76 | virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName ) = 0; |
---|
| 77 | }; |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | @remarks |
---|
| 81 | Log class for writing debug/log data to files. |
---|
| 82 | @note |
---|
| 83 | <br>Should not be used directly, but trough the LogManager class. |
---|
| 84 | */ |
---|
| 85 | class _OgreExport Log |
---|
| 86 | { |
---|
| 87 | protected: |
---|
| 88 | std::ofstream mfpLog; |
---|
| 89 | LoggingLevel mLogLevel; |
---|
| 90 | bool mDebugOut; |
---|
| 91 | bool mSuppressFile; |
---|
| 92 | String mLogName; |
---|
| 93 | |
---|
| 94 | typedef std::vector<LogListener*> mtLogListener; |
---|
| 95 | mtLogListener mListeners; |
---|
| 96 | |
---|
| 97 | public: |
---|
| 98 | OGRE_AUTO_MUTEX // public to allow external locking |
---|
| 99 | /** |
---|
| 100 | @remarks |
---|
| 101 | Usual constructor - called by LogManager. |
---|
| 102 | */ |
---|
| 103 | Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false); |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | @remarks |
---|
| 107 | Default destructor. |
---|
| 108 | */ |
---|
| 109 | ~Log(); |
---|
| 110 | |
---|
| 111 | /// Return the name of the log |
---|
| 112 | const String& getName() const { return mLogName; } |
---|
| 113 | /// Get whether debug output is enabled for this log |
---|
| 114 | bool isDebugOutputEnabled() const { return mDebugOut; } |
---|
| 115 | /// Get whether file output is suppressed for this log |
---|
| 116 | bool isFileOutputSuppressed() const { return mSuppressFile; } |
---|
| 117 | |
---|
| 118 | /** Log a message to the debugger and to log file (the default is |
---|
| 119 | "<code>OGRE.log</code>"), |
---|
| 120 | */ |
---|
| 121 | void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false ); |
---|
| 122 | |
---|
| 123 | /** |
---|
| 124 | @remarks |
---|
| 125 | Sets the level of the log detail. |
---|
| 126 | */ |
---|
| 127 | void setLogDetail(LoggingLevel ll); |
---|
| 128 | /** Gets the level of the log detail. |
---|
| 129 | */ |
---|
| 130 | LoggingLevel getLogDetail() const { return mLogLevel; } |
---|
| 131 | /** |
---|
| 132 | @remarks |
---|
| 133 | Register a listener to this log |
---|
| 134 | @param |
---|
| 135 | A valid listener derived class |
---|
| 136 | */ |
---|
| 137 | void addListener(LogListener* listener); |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | @remarks |
---|
| 141 | Unregister a listener from this log |
---|
| 142 | @param |
---|
| 143 | A valid listener derived class |
---|
| 144 | */ |
---|
| 145 | void removeListener(LogListener* listener); |
---|
| 146 | }; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | #endif |
---|