OGRE  1.9.0
OgreLog.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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"
36
37#if OGRE_PLATFORM == OGRE_PLATFORM_NACL
38namespace pp
39{
40 class Instance;
41}
42#endif
43
44namespace Ogre {
45
52 // LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged
53 #define OGRE_LOG_THRESHOLD 4
54
58 {
59 LL_LOW = 1,
61 LL_BOREME = 3
62 };
63
67 {
70 LML_CRITICAL = 3
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;
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
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);
163 void setTimeStampEnabled(bool timeStamp);
166 LoggingLevel getLogDetail() const { return mLogLevel; }
173 void addListener(LogListener* listener);
174
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
243 Stream& operator<< (const Flush& v)
244 {
245 (void)v;
246 mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
247 mCache.str(StringUtil::BLANK);
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
#define _OgreExport
#define _OgrePrivate
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
virtual ~LogListener()
Definition OgreLog.h:77
virtual void messageLogged(const String &message, LogMessageLevel lml, bool maskDebug, const String &logName, bool &skipThisMessage)=0
Stream object which targets a log.
Definition OgreLog.h:202
StringUtil::StrStreamType BaseStream
Definition OgreLog.h:207
LogMessageLevel mLevel
Definition OgreLog.h:205
BaseStream mCache
Definition OgreLog.h:208
Stream(const Stream &rhs)
Definition OgreLog.h:221
Stream(Log *target, LogMessageLevel lml, bool maskDebug)
Definition OgreLog.h:215
Log(const String &name, bool debugOutput=true, bool suppressFileOutput=false)
void logMessage(const String &message, LogMessageLevel lml=LML_NORMAL, bool maskDebug=false)
Log a message to the debugger and to log file (the default is "<code>OGRE.log</code>"),...
bool isFileOutputSuppressed() const
Get whether file output is suppressed for this log.
Definition OgreLog.h:137
void addListener(LogListener *listener)
std::ofstream mLog
Definition OgreLog.h:106
bool mSuppressFile
Definition OgreLog.h:109
void setTimeStampEnabled(bool timeStamp)
const String & getName() const
Return the name of the log.
Definition OgreLog.h:133
void setLogDetail(LoggingLevel ll)
void removeListener(LogListener *listener)
bool mDebugOut
Definition OgreLog.h:108
bool isTimeStampEnabled() const
Get whether time stamps are printed for this log.
Definition OgreLog.h:139
bool mTimeStamp
Definition OgreLog.h:110
OGRE_AUTO_MUTEX
Definition OgreLog.h:119
mtLogListener mListeners
Definition OgreLog.h:114
LoggingLevel mLogLevel
Definition OgreLog.h:107
void setDebugOutputEnabled(bool debugOutput)
Stream stream(LogMessageLevel lml=LML_NORMAL, bool maskDebug=false)
Get a stream object targeting this log.
LoggingLevel getLogDetail() const
Gets the level of the log detail.
Definition OgreLog.h:166
String mLogName
Definition OgreLog.h:111
bool isDebugOutputEnabled() const
Get whether debug output is enabled for this log.
Definition OgreLog.h:135
vector< LogListener * >::type mtLogListener
Definition OgreLog.h:113
StringStream StrStreamType
Definition OgreString.h:78
LoggingLevel
The level of detail to which the log will go into.
Definition OgreLog.h:58
LogMessageLevel
The importance of a logged message.
Definition OgreLog.h:67
@ LL_LOW
Definition OgreLog.h:59
@ LL_BOREME
Definition OgreLog.h:61
@ LL_NORMAL
Definition OgreLog.h:60
@ LML_TRIVIAL
Definition OgreLog.h:68
@ LML_CRITICAL
Definition OgreLog.h:70
@ LML_NORMAL
Definition OgreLog.h:69
_StringBase String
Simple type to indicate a flush of the stream to the log.
Definition OgreLog.h:213
std::vector< T, A > type