OGRE  2.0
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-2014 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 "OgreCommon.h"
35 #include "OgreHeaderPrefix.h"
36 
37 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL
38 namespace pp
39 {
40  class Instance;
41 }
42 #endif
43 
44 namespace Ogre {
45 
52  // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged
53  #define OGRE_LOG_THRESHOLD 4
54 
58  {
59  LL_LOW = 1,
60  LL_NORMAL = 2,
62  };
63 
67  {
71  };
72 
75  {
76  public:
77  virtual ~LogListener() {}
78 
93  virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName, bool& skipThisMessage ) = 0;
94  };
95 
96 
103  class _OgreExport Log : public LogAlloc
104  {
105  protected:
106  std::ofstream mLog;
108  bool mDebugOut;
112 
115  public:
116 
117  class Stream;
118 
119  OGRE_AUTO_MUTEX; // public to allow external locking
124  Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false);
125 
130  ~Log();
131 
133  const String& getName() const { return mLogName; }
135  bool isDebugOutputEnabled() const { return mDebugOut; }
137  bool isFileOutputSuppressed() const { return mSuppressFile; }
139  bool isTimeStampEnabled() const { return mTimeStamp; }
140 
144  void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false );
145 
147  Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false);
148 
153  void setDebugOutputEnabled(bool debugOutput);
158  void setLogDetail(LoggingLevel ll);
163  void setTimeStampEnabled(bool timeStamp);
166  LoggingLevel getLogDetail() const { return mLogLevel; }
173  void addListener(LogListener* listener);
174 
181  void removeListener(LogListener* listener);
182 
202  {
203  protected:
209 
210  public:
211 
213  struct Flush {};
214 
215  Stream(Log* target, LogMessageLevel lml, bool maskDebug)
216  :mTarget(target), mLevel(lml), mMaskDebug(maskDebug)
217  {
218 
219  }
220  // copy constructor
221  Stream(const Stream& rhs)
222  : mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug)
223  {
224  // explicit copy of stream required, gcc doesn't like implicit
225  mCache.str(rhs.mCache.str());
226  }
228  {
229  // flush on destroy
230  if (mCache.tellp() > 0)
231  {
232  mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
233  }
234  }
235 
236  template <typename T>
237  Stream& operator<< (const T& v)
238  {
239  mCache << v;
240  return *this;
241  }
242 
244  {
245  (void)v;
246  mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
247  mCache.str(BLANKSTRING);
248  return *this;
249  }
250 
251 
252  };
253 #if OGRE_PLATFORM == OGRE_PLATFORM_NACL
254  protected:
255  static pp::Instance* mInstance;
256  public:
257  static void setInstance(pp::Instance* instance) {mInstance = instance;};
258 #endif
259 
260  };
263 }
264 
265 #include "OgreHeaderSuffix.h"
266 
267 #endif
std::ofstream mLog
Definition: OgreLog.h:106
#define _OgreExport
Definition: OgrePlatform.h:255
LoggingLevel mLogLevel
Definition: OgreLog.h:107
Stream(const Stream &rhs)
Definition: OgreLog.h:221
vector< LogListener * >::type mtLogListener
Definition: OgreLog.h:113
LoggingLevel
The level of detail to which the log will go into.
Definition: OgreLog.h:57
LoggingLevel getLogDetail() const
Gets the level of the log detail.
Definition: OgreLog.h:166
Stream object which targets a log.
Definition: OgreLog.h:201
String mLogName
Definition: OgreLog.h:111
bool mSuppressFile
Definition: OgreLog.h:109
const String BLANKSTRING
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreCommon.h:574
_StringStreamBase StringStream
virtual ~LogListener()
Definition: OgreLog.h:77
Simple type to indicate a flush of the stream to the log.
Definition: OgreLog.h:213
StringStream BaseStream
Definition: OgreLog.h:207
bool isFileOutputSuppressed() const
Get whether file output is suppressed for this log.
Definition: OgreLog.h:137
bool isTimeStampEnabled() const
Get whether time stamps are printed for this log.
Definition: OgreLog.h:139
BaseStream mCache
Definition: OgreLog.h:208
LogMessageLevel
The importance of a logged message.
Definition: OgreLog.h:66
#define _OgrePrivate
Definition: OgrePlatform.h:256
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:133
virtual void messageLogged(const String &message, LogMessageLevel lml, bool maskDebug, const String &logName, bool &skipThisMessage)=0
LogMessageLevel mLevel
Definition: OgreLog.h:205
OGRE_AUTO_MUTEX
Definition: OgreLog.h:117
bool mTimeStamp
Definition: OgreLog.h:110
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:666
bool mDebugOut
Definition: OgreLog.h:108
_StringBase String
Definition: OgreCommon.h:53
bool isDebugOutputEnabled() const
Get whether debug output is enabled for this log.
Definition: OgreLog.h:135
mtLogListener mListeners
Definition: OgreLog.h:114
Stream(Log *target, LogMessageLevel lml, bool maskDebug)
Definition: OgreLog.h:215