OgreLog.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Log_H__
#define __Log_H__
#include "OgrePrerequisites.h"
#include "OgreString.h"
#include "OgreHeaderPrefix.h"
#include "Threading/OgreThreadHeaders.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_NACL
namespace pp
{
class Instance;
}
#endif
namespace Ogre {
// LogMessageLevel + LoggingLevel > OGRE_LOG_THRESHOLD = message logged
#define OGRE_LOG_THRESHOLD 4
enum LoggingLevel
{
LL_LOW = 1,
LL_NORMAL = 2,
LL_BOREME = 3
};
enum LogMessageLevel
{
LML_TRIVIAL = 1,
LML_NORMAL = 2,
LML_CRITICAL = 3
};
class LogListener
{
public:
virtual ~LogListener() {}
virtual void messageLogged( const String& message, LogMessageLevel lml, bool maskDebug, const String &logName, bool& skipThisMessage ) = 0;
};
class _OgreExport Log : public LogAlloc
{
protected:
std::ofstream mLog;
LoggingLevel mLogLevel;
bool mDebugOut;
bool mSuppressFile;
bool mTimeStamp;
String mLogName;
typedef vector<LogListener*>::type mtLogListener;
mtLogListener mListeners;
public:
class Stream;
OGRE_AUTO_MUTEX; // public to allow external locking
Log( const String& name, bool debugOutput = true, bool suppressFileOutput = false);
~Log();
const String& getName() const { return mLogName; }
bool isDebugOutputEnabled() const { return mDebugOut; }
bool isFileOutputSuppressed() const { return mSuppressFile; }
bool isTimeStampEnabled() const { return mTimeStamp; }
void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL, bool maskDebug = false );
Stream stream(LogMessageLevel lml = LML_NORMAL, bool maskDebug = false);
void setDebugOutputEnabled(bool debugOutput);
void setLogDetail(LoggingLevel ll);
void setTimeStampEnabled(bool timeStamp);
LoggingLevel getLogDetail() const { return mLogLevel; }
void addListener(LogListener* listener);
void removeListener(LogListener* listener);
class _OgrePrivate Stream
{
protected:
Log* mTarget;
LogMessageLevel mLevel;
bool mMaskDebug;
typedef StringUtil::StrStreamType BaseStream;
BaseStream mCache;
public:
struct Flush {};
Stream(Log* target, LogMessageLevel lml, bool maskDebug)
:mTarget(target), mLevel(lml), mMaskDebug(maskDebug)
{
}
// copy constructor
Stream(const Stream& rhs)
: mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug)
{
// explicit copy of stream required, gcc doesn't like implicit
mCache.str(rhs.mCache.str());
}
~Stream()
{
// flush on destroy
if (mCache.tellp() > 0)
{
mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
}
}
template <typename T>
Stream& operator<< (const T& v)
{
mCache << v;
return *this;
}
Stream& operator<< (const Flush& v)
{
(void)v;
mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
mCache.str(StringUtil::BLANK);
return *this;
}
};
#if OGRE_PLATFORM == OGRE_PLATFORM_NACL
protected:
static pp::Instance* mInstance;
public:
static void setInstance(pp::Instance* instance) {mInstance = instance;};
#endif
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::LML_CRITICAL
Definition: OgreLog.h:70
Ogre::LogMessageLevel
LogMessageLevel
The importance of a logged message.
Definition: OgreLog.h:66
Ogre::Log::mLog
std::ofstream mLog
Definition: OgreLog.h:106
Ogre::Log::mLogLevel
LoggingLevel mLogLevel
Definition: OgreLog.h:107
Ogre::Log::Stream::mLevel
LogMessageLevel mLevel
Definition: OgreLog.h:205
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Log::Stream
Stream object which targets a log.
Definition: OgreLog.h:201
Ogre::Log::Stream::mCache
BaseStream mCache
Definition: OgreLog.h:208
Ogre::LML_TRIVIAL
Definition: OgreLog.h:68
Ogre::Log::Stream::Stream
Stream(Log *target, LogMessageLevel lml, bool maskDebug)
Definition: OgreLog.h:215
Ogre::Log::Stream::Flush
Simple type to indicate a flush of the stream to the log.
Definition: OgreLog.h:213
Ogre::Log::isFileOutputSuppressed
bool isFileOutputSuppressed() const
Get whether file output is suppressed for this log.
Definition: OgreLog.h:137
OgreString.h
Ogre::Log::mTimeStamp
bool mTimeStamp
Definition: OgreLog.h:110
Ogre::StringUtil::StrStreamType
StringStream StrStreamType
Definition: OgreString.h:78
Ogre::Log::Stream::mMaskDebug
bool mMaskDebug
Definition: OgreLog.h:206
Ogre::LL_LOW
Definition: OgreLog.h:59
Ogre::Log::mLogName
String mLogName
Definition: OgreLog.h:111
Ogre::Log::isTimeStampEnabled
bool isTimeStampEnabled() const
Get whether time stamps are printed for this log.
Definition: OgreLog.h:139
Ogre::Log::OGRE_AUTO_MUTEX
OGRE_AUTO_MUTEX
Definition: OgreLog.h:117
Ogre::Log::mtLogListener
vector< LogListener * >::type mtLogListener
Definition: OgreLog.h:113
OgrePrerequisites.h
Ogre::LoggingLevel
LoggingLevel
The level of detail to which the log will go into.
Definition: OgreLog.h:57
_OgrePrivate
#define _OgrePrivate
Definition: OgrePlatform.h:258
Ogre::Log::getLogDetail
LoggingLevel getLogDetail() const
Gets the level of the log detail.
Definition: OgreLog.h:166
Ogre::operator<<
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:636
Ogre::LL_BOREME
Definition: OgreLog.h:61
Ogre::Log::mListeners
mtLogListener mListeners
Definition: OgreLog.h:114
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::LML_NORMAL
Definition: OgreLog.h:69
OgreHeaderSuffix.h
Ogre::Log::logMessage
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>"),.
Ogre::Log
Definition: OgreLog.h:103
OgreThreadHeaders.h
Ogre::Log::Stream::~Stream
~Stream()
Definition: OgreLog.h:227
Ogre::LL_NORMAL
Definition: OgreLog.h:60
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::LogListener
Definition: OgreLog.h:74
Ogre::Log::isDebugOutputEnabled
bool isDebugOutputEnabled() const
Get whether debug output is enabled for this log.
Definition: OgreLog.h:135
Ogre::vector
Definition: OgrePrerequisites.h:491
OgreHeaderPrefix.h
Ogre::Log::mDebugOut
bool mDebugOut
Definition: OgreLog.h:108
Ogre::Log::Stream::BaseStream
StringUtil::StrStreamType BaseStream
Definition: OgreLog.h:207
Ogre::Log::Stream::mTarget
Log * mTarget
Definition: OgreLog.h:204
Ogre::Log::Stream::Stream
Stream(const Stream &rhs)
Definition: OgreLog.h:221
Ogre::Log::getName
const String & getName() const
Return the name of the log.
Definition: OgreLog.h:133
Ogre::LogListener::~LogListener
virtual ~LogListener()
Definition: OgreLog.h:77
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Log::mSuppressFile
bool mSuppressFile
Definition: OgreLog.h:109

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.