OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 
35 namespace Ogre {
36 
43  // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged
44  #define OGRE_LOG_THRESHOLD 4
45 
49  {
50  LL_LOW = 1,
51  LL_NORMAL = 2,
53  };
54 
58  {
62  };
63 
66  {
67  public:
68  virtual ~LogListener() {}
69 
82  virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName ) = 0;
83  };
84 
85 
92  class _OgreExport Log : public LogAlloc
93  {
94  protected:
95  std::ofstream mfpLog;
97  bool mDebugOut;
99  bool mTimeStamp;
101 
104 
105  public:
106 
107  class Stream;
108 
109  OGRE_AUTO_MUTEX // public to allow external locking
114  Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false);
115 
120  ~Log();
121 
123  const String& getName() const { return mLogName; }
125  bool isDebugOutputEnabled() const { return mDebugOut; }
127  bool isFileOutputSuppressed() const { return mSuppressFile; }
129  bool isTimeStampEnabled() const { return mTimeStamp; }
130 
134  void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false );
135 
137  Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false);
138 
143  void setDebugOutputEnabled(bool debugOutput);
148  void setLogDetail(LoggingLevel ll);
153  void setTimeStampEnabled(bool timeStamp);
156  LoggingLevel getLogDetail() const { return mLogLevel; }
163  void addListener(LogListener* listener);
164 
171  void removeListener(LogListener* listener);
172 
192  {
193  protected:
199 
200  public:
201 
203  struct Flush {};
204 
205  Stream(Log* target, LogMessageLevel lml, bool maskDebug)
206  :mTarget(target), mLevel(lml), mMaskDebug(maskDebug)
207  {
208 
209  }
210  // copy constructor
211  Stream(const Stream& rhs)
212  : mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug)
213  {
214  // explicit copy of stream required, gcc doesn't like implicit
215  mCache.str(rhs.mCache.str());
216  }
218  {
219  // flush on destroy
220  if (mCache.tellp() > 0)
221  {
222  mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
223  }
224  }
225 
226  template <typename T>
227  Stream& operator<< (const T& v)
228  {
229  mCache << v;
230  return *this;
231  }
232 
234  {
235  (void)v;
236  mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
237  mCache.str(StringUtil::BLANK);
238  return *this;
239  }
240 
241 
242  };
243 
244  };
247 }
248 
249 #endif
#define OGRE_AUTO_MUTEX
#define _OgreExport
Definition: OgrePlatform.h:203
LoggingLevel mLogLevel
Definition: OgreLog.h:96
Stream(const Stream &rhs)
Definition: OgreLog.h:211
vector< LogListener * >::type mtLogListener
Definition: OgreLog.h:102
LoggingLevel
The level of detail to which the log will go into.
Definition: OgreLog.h:48
StringStream StrStreamType
Definition: OgreString.h:77
LoggingLevel getLogDetail() const
Gets the level of the log detail.
Definition: OgreLog.h:156
Stream object which targets a log.
Definition: OgreLog.h:191
StringUtil::StrStreamType BaseStream
Definition: OgreLog.h:197
String mLogName
Definition: OgreLog.h:100
bool mSuppressFile
Definition: OgreLog.h:98
virtual ~LogListener()
Definition: OgreLog.h:68
Simple type to indicate a flush of the stream to the log.
Definition: OgreLog.h:203
std::ofstream mfpLog
Definition: OgreLog.h:95
bool isFileOutputSuppressed() const
Get whether file output is suppressed for this log.
Definition: OgreLog.h:127
virtual void messageLogged(const String &message, LogMessageLevel lml, bool maskDebug, const String &logName)=0
bool isTimeStampEnabled() const
Get whether time stamps are printed for this log.
Definition: OgreLog.h:129
BaseStream mCache
Definition: OgreLog.h:198
LogMessageLevel
The importance of a logged message.
Definition: OgreLog.h:57
#define _OgrePrivate
Definition: OgrePlatform.h:204
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:123
LogMessageLevel mLevel
Definition: OgreLog.h:195
bool mTimeStamp
Definition: OgreLog.h:99
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:610
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:180
bool mDebugOut
Definition: OgreLog.h:97
_StringBase String
bool isDebugOutputEnabled() const
Get whether debug output is enabled for this log.
Definition: OgreLog.h:125
mtLogListener mListeners
Definition: OgreLog.h:103
Stream(Log *target, LogMessageLevel lml, bool maskDebug)
Definition: OgreLog.h:205