00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 00029 #ifndef __Log_H__ 00030 #define __Log_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreString.h" 00034 00035 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL 00036 namespace pp 00037 { 00038 class Instance; 00039 } 00040 #endif 00041 00042 namespace Ogre { 00043 00050 // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged 00051 #define OGRE_LOG_THRESHOLD 4 00052 00055 enum LoggingLevel 00056 { 00057 LL_LOW = 1, 00058 LL_NORMAL = 2, 00059 LL_BOREME = 3 00060 }; 00061 00064 enum LogMessageLevel 00065 { 00066 LML_TRIVIAL = 1, 00067 LML_NORMAL = 2, 00068 LML_CRITICAL = 3 00069 }; 00070 00072 class LogListener 00073 { 00074 public: 00075 virtual ~LogListener() {} 00076 00091 virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName, bool& skipThisMessage ) = 0; 00092 }; 00093 00094 00101 class _OgreExport Log : public LogAlloc 00102 { 00103 protected: 00104 std::ofstream mLog; 00105 LoggingLevel mLogLevel; 00106 bool mDebugOut; 00107 bool mSuppressFile; 00108 bool mTimeStamp; 00109 String mLogName; 00110 00111 typedef vector<LogListener*>::type mtLogListener; 00112 mtLogListener mListeners; 00113 public: 00114 00115 class Stream; 00116 00117 OGRE_AUTO_MUTEX // public to allow external locking 00122 Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false); 00123 00128 ~Log(); 00129 00131 const String& getName() const { return mLogName; } 00133 bool isDebugOutputEnabled() const { return mDebugOut; } 00135 bool isFileOutputSuppressed() const { return mSuppressFile; } 00137 bool isTimeStampEnabled() const { return mTimeStamp; } 00138 00142 void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false ); 00143 00145 Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false); 00146 00151 void setDebugOutputEnabled(bool debugOutput); 00156 void setLogDetail(LoggingLevel ll); 00161 void setTimeStampEnabled(bool timeStamp); 00164 LoggingLevel getLogDetail() const { return mLogLevel; } 00171 void addListener(LogListener* listener); 00172 00179 void removeListener(LogListener* listener); 00180 00199 class _OgrePrivate Stream 00200 { 00201 protected: 00202 Log* mTarget; 00203 LogMessageLevel mLevel; 00204 bool mMaskDebug; 00205 typedef StringUtil::StrStreamType BaseStream; 00206 BaseStream mCache; 00207 00208 public: 00209 00211 struct Flush {}; 00212 00213 Stream(Log* target, LogMessageLevel lml, bool maskDebug) 00214 :mTarget(target), mLevel(lml), mMaskDebug(maskDebug) 00215 { 00216 00217 } 00218 // copy constructor 00219 Stream(const Stream& rhs) 00220 : mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug) 00221 { 00222 // explicit copy of stream required, gcc doesn't like implicit 00223 mCache.str(rhs.mCache.str()); 00224 } 00225 ~Stream() 00226 { 00227 // flush on destroy 00228 if (mCache.tellp() > 0) 00229 { 00230 mTarget->logMessage(mCache.str(), mLevel, mMaskDebug); 00231 } 00232 } 00233 00234 template <typename T> 00235 Stream& operator<< (const T& v) 00236 { 00237 mCache << v; 00238 return *this; 00239 } 00240 00241 Stream& operator<< (const Flush& v) 00242 { 00243 (void)v; 00244 mTarget->logMessage(mCache.str(), mLevel, mMaskDebug); 00245 mCache.str(StringUtil::BLANK); 00246 return *this; 00247 } 00248 00249 00250 }; 00251 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL 00252 protected: 00253 static pp::Instance* mInstance; 00254 public: 00255 static void setInstance(pp::Instance* instance) {mInstance = instance;}; 00256 #endif 00257 00258 }; 00261 } 00262 00263 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012