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-2013 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 #include "OgreHeaderPrefix.h" 00035 #include "Threading/OgreThreadHeaders.h" 00036 00037 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL 00038 namespace pp 00039 { 00040 class Instance; 00041 } 00042 #endif 00043 00044 namespace Ogre { 00045 00052 // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged 00053 #define OGRE_LOG_THRESHOLD 4 00054 00057 enum LoggingLevel 00058 { 00059 LL_LOW = 1, 00060 LL_NORMAL = 2, 00061 LL_BOREME = 3 00062 }; 00063 00066 enum LogMessageLevel 00067 { 00068 LML_TRIVIAL = 1, 00069 LML_NORMAL = 2, 00070 LML_CRITICAL = 3 00071 }; 00072 00074 class LogListener 00075 { 00076 public: 00077 virtual ~LogListener() {} 00078 00093 virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName, bool& skipThisMessage ) = 0; 00094 }; 00095 00096 00103 class _OgreExport Log : public LogAlloc 00104 { 00105 protected: 00106 std::ofstream mLog; 00107 LoggingLevel mLogLevel; 00108 bool mDebugOut; 00109 bool mSuppressFile; 00110 bool mTimeStamp; 00111 String mLogName; 00112 00113 typedef vector<LogListener*>::type mtLogListener; 00114 mtLogListener mListeners; 00115 public: 00116 00117 class Stream; 00118 00119 OGRE_AUTO_MUTEX; // public to allow external locking 00124 Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false); 00125 00130 ~Log(); 00131 00133 const String& getName() const { return mLogName; } 00135 bool isDebugOutputEnabled() const { return mDebugOut; } 00137 bool isFileOutputSuppressed() const { return mSuppressFile; } 00139 bool isTimeStampEnabled() const { return mTimeStamp; } 00140 00144 void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false ); 00145 00147 Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false); 00148 00153 void setDebugOutputEnabled(bool debugOutput); 00158 void setLogDetail(LoggingLevel ll); 00163 void setTimeStampEnabled(bool timeStamp); 00166 LoggingLevel getLogDetail() const { return mLogLevel; } 00173 void addListener(LogListener* listener); 00174 00181 void removeListener(LogListener* listener); 00182 00201 class _OgrePrivate Stream 00202 { 00203 protected: 00204 Log* mTarget; 00205 LogMessageLevel mLevel; 00206 bool mMaskDebug; 00207 typedef StringUtil::StrStreamType BaseStream; 00208 BaseStream mCache; 00209 00210 public: 00211 00213 struct Flush {}; 00214 00215 Stream(Log* target, LogMessageLevel lml, bool maskDebug) 00216 :mTarget(target), mLevel(lml), mMaskDebug(maskDebug) 00217 { 00218 00219 } 00220 // copy constructor 00221 Stream(const Stream& rhs) 00222 : mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug) 00223 { 00224 // explicit copy of stream required, gcc doesn't like implicit 00225 mCache.str(rhs.mCache.str()); 00226 } 00227 ~Stream() 00228 { 00229 // flush on destroy 00230 if (mCache.tellp() > 0) 00231 { 00232 mTarget->logMessage(mCache.str(), mLevel, mMaskDebug); 00233 } 00234 } 00235 00236 template <typename T> 00237 Stream& operator<< (const T& v) 00238 { 00239 mCache << v; 00240 return *this; 00241 } 00242 00243 Stream& operator<< (const Flush& v) 00244 { 00245 (void)v; 00246 mTarget->logMessage(mCache.str(), mLevel, mMaskDebug); 00247 mCache.str(StringUtil::BLANK); 00248 return *this; 00249 } 00250 00251 00252 }; 00253 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL 00254 protected: 00255 static pp::Instance* mInstance; 00256 public: 00257 static void setInstance(pp::Instance* instance) {mInstance = instance;}; 00258 #endif 00259 00260 }; 00263 } 00264 00265 #include "OgreHeaderSuffix.h" 00266 00267 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:44