OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreLog.h
Go to the documentation of this file.
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 __Log_H__
30 #define __Log_H__
31 
32 #include "OgrePrerequisites.h"
33 #include "OgreString.h"
34 #include "OgreHeaderPrefix.h"
35 
36 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL
37 namespace pp
38 {
39  class Instance;
40 }
41 #endif
42 
43 namespace Ogre {
44 
51  // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged
52  #define OGRE_LOG_THRESHOLD 4
53 
57  {
58  LL_LOW = 1,
59  LL_NORMAL = 2,
61  };
62 
66  {
70  };
71 
74  {
75  public:
76  virtual ~LogListener() {}
77 
92  virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName, bool& skipThisMessage ) = 0;
93  };
94 
95 
102  class _OgreExport Log : public LogAlloc
103  {
104  protected:
105  std::ofstream mLog;
107  bool mDebugOut;
111 
114  public:
115 
116  class Stream;
117 
118  OGRE_AUTO_MUTEX // public to allow external locking
123  Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false);
124 
129  ~Log();
130 
132  const String& getName() const { return mLogName; }
134  bool isDebugOutputEnabled() const { return mDebugOut; }
136  bool isFileOutputSuppressed() const { return mSuppressFile; }
138  bool isTimeStampEnabled() const { return mTimeStamp; }
139 
143  void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false );
144 
146  Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false);
147 
152  void setDebugOutputEnabled(bool debugOutput);
157  void setLogDetail(LoggingLevel ll);
162  void setTimeStampEnabled(bool timeStamp);
165  LoggingLevel getLogDetail() const { return mLogLevel; }
172  void addListener(LogListener* listener);
173 
180  void removeListener(LogListener* listener);
181 
201  {
202  protected:
208 
209  public:
210 
212  struct Flush {};
213 
214  Stream(Log* target, LogMessageLevel lml, bool maskDebug)
215  :mTarget(target), mLevel(lml), mMaskDebug(maskDebug)
216  {
217 
218  }
219  // copy constructor
220  Stream(const Stream& rhs)
221  : mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug)
222  {
223  // explicit copy of stream required, gcc doesn't like implicit
224  mCache.str(rhs.mCache.str());
225  }
227  {
228  // flush on destroy
229  if (mCache.tellp() > 0)
230  {
231  mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
232  }
233  }
234 
235  template <typename T>
236  Stream& operator<< (const T& v)
237  {
238  mCache << v;
239  return *this;
240  }
241 
243  {
244  (void)v;
245  mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
246  mCache.str(StringUtil::BLANK);
247  return *this;
248  }
249 
250 
251  };
252 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL
253  protected:
254  static pp::Instance* mInstance;
255  public:
256  static void setInstance(pp::Instance* instance) {mInstance = instance;};
257 #endif
258 
259  };
262 }
263 
264 #include "OgreHeaderSuffix.h"
265 
266 #endif
#define OGRE_AUTO_MUTEX
std::ofstream mLog
Definition: OgreLog.h:105
#define _OgreExport
Definition: OgrePlatform.h:233
LoggingLevel mLogLevel
Definition: OgreLog.h:106
Stream(const Stream &rhs)
Definition: OgreLog.h:220
vector< LogListener * >::type mtLogListener
Definition: OgreLog.h:112
LoggingLevel
The level of detail to which the log will go into.
Definition: OgreLog.h:56
StringStream StrStreamType
Definition: OgreString.h:78
LoggingLevel getLogDetail() const
Gets the level of the log detail.
Definition: OgreLog.h:165
Stream object which targets a log.
Definition: OgreLog.h:200
StringUtil::StrStreamType BaseStream
Definition: OgreLog.h:206
String mLogName
Definition: OgreLog.h:110
bool mSuppressFile
Definition: OgreLog.h:108
virtual ~LogListener()
Definition: OgreLog.h:76
Simple type to indicate a flush of the stream to the log.
Definition: OgreLog.h:212
bool isFileOutputSuppressed() const
Get whether file output is suppressed for this log.
Definition: OgreLog.h:136
bool isTimeStampEnabled() const
Get whether time stamps are printed for this log.
Definition: OgreLog.h:138
BaseStream mCache
Definition: OgreLog.h:207
LogMessageLevel
The importance of a logged message.
Definition: OgreLog.h:65
#define _OgrePrivate
Definition: OgrePlatform.h:234
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
const String & getName() const
Return the name of the log.
Definition: OgreLog.h:132
virtual void messageLogged(const String &message, LogMessageLevel lml, bool maskDebug, const String &logName, bool &skipThisMessage)=0
LogMessageLevel mLevel
Definition: OgreLog.h:204
bool mTimeStamp
Definition: OgreLog.h:109
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:639
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:196
bool mDebugOut
Definition: OgreLog.h:107
_StringBase String
bool isDebugOutputEnabled() const
Get whether debug output is enabled for this log.
Definition: OgreLog.h:134
mtLogListener mListeners
Definition: OgreLog.h:113
Stream(Log *target, LogMessageLevel lml, bool maskDebug)
Definition: OgreLog.h:214