ogre log
来源:互联网 发布:apache官方文档 编辑:程序博客网 时间:2024/06/02 00:07
1:#ifndef __Log_H__
#define __Log_H__
#include "OgrePrerequisites.h"
#include "OgreString.h"
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 ) = 0;
};
class _OgreExport Log : public LogAlloc
{
protected:
std::ofstream mfpLog;
LoggingLevel mLogLevel;
bool mDebugOut;
bool mSuppressFile;
String mLogName;
typedef std::vector<LogListener*> 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();
/// Return the name of the log
const String& getName() const { return mLogName; }
/// Get whether debug output is enabled for this log
bool isDebugOutputEnabled() const { return mDebugOut; }
/// Get whether file output is suppressed for this log
bool isFileOutputSuppressed() const { return mSuppressFile; }
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);
LoggingLevel getLogDetail() const { return mLogLevel; }
void addListener(LogListener* listener);
void removeListener(LogListener* listener);
class 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)
{
}
Stream(const Stream& rhs)
: mTarget(rhs.mTarget), mLevel(rhs.mLevel), mMaskDebug(rhs.mMaskDebug)
{
mCache.str(rhs.mCache.str());
}
~Stream()
{
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)
{
mTarget->logMessage(mCache.str(), mLevel, mMaskDebug);
mCache.str(StringUtil::BLANK);
return *this;
}
};
};
}
#endif
2#include "OgreStableHeaders.h"
#include "OgreLog.h"
#include "OgreLogManager.h"
#include "OgreString.h"
namespace Ogre
{
Log::Log( const String& name, bool debuggerOuput, bool suppressFile ) :
mLogLevel(LL_NORMAL), mDebugOut(debuggerOuput),
mSuppressFile(suppressFile), mLogName(name)
{
if (!mSuppressFile)
{
mfpLog.open(name.c_str());
}
}
Log::~Log()
{
OGRE_LOCK_AUTO_MUTEX
if (!mSuppressFile)
{
mfpLog.close();
}
}
void Log::logMessage( const String& message, LogMessageLevel lml, bool maskDebug )
{
OGRE_LOCK_AUTO_MUTEX
if ((mLogLevel + lml) >= OGRE_LOG_THRESHOLD)
{
for( mtLogListener::iterator i = mListeners.begin(); i != mListeners.end(); ++i )
(*i)->messageLogged( message, lml, maskDebug, mLogName );
if (mDebugOut && !maskDebug)
std::cerr << message << std::endl;
// Write time into log
if (!mSuppressFile)
{
struct tm *pTime;
time_t ctTime; time(&ctTime);
pTime = localtime( &ctTime );
mfpLog << std::setw(2) << std::setfill('0') << pTime->tm_hour
<< ":" << std::setw(2) << std::setfill('0') << pTime->tm_min
<< ":" << std::setw(2) << std::setfill('0') << pTime->tm_sec
<< ": " << message << std::endl;
mfpLog.flush();
}
}
}
void Log::setDebugOutputEnabled(bool debugOutput)
{
OGRE_LOCK_AUTO_MUTEX
mDebugOut = debugOutput;
}
void Log::setLogDetail(LoggingLevel ll)
{
OGRE_LOCK_AUTO_MUTEX
mLogLevel = ll;
}
void Log::addListener(LogListener* listener)
{
OGRE_LOCK_AUTO_MUTEX
mListeners.push_back(listener);
}
void Log::removeListener(LogListener* listener)
{
OGRE_LOCK_AUTO_MUTEX
mListeners.erase(std::find(mListeners.begin(), mListeners.end(), listener));
}
Log::Stream Log::stream(LogMessageLevel lml, bool maskDebug)
{
return Stream(this, lml, maskDebug);
}
}
3: #ifndef __LogManager_H__
#define __LogManager_H__
#include "OgrePrerequisites.h"
#include "OgreLog.h"
#include "OgreSingleton.h"
#include "OgreString.h"
namespace Ogre
{
class _OgreExport LogManager : public Singleton<LogManager>, public LogAlloc
{
protected:
typedef std::map<String, Log*, std::less<String> > LogList;
LogList mLogs;
Log* mDefaultLog;
public:
OGRE_AUTO_MUTEX // public to allow external locking
LogManager();
~LogManager();
Log* createLog( const String& name, bool defaultLog = false, bool debuggerOutput = true,
bool suppressFileOutput = false);
Log* getLog( const String& name);
Log* getDefaultLog();
void destroyLog(const String& name);
void destroyLog(Log* log);
Log* setDefaultLog(Log* newLog);
void logMessage( const String& message, LogMessageLevel lml = LML_NORMAL,
bool maskDebug = false);
void logMessage( LogMessageLevel lml, const String& message,
bool maskDebug = false) { logMessage(message, lml, maskDebug); }
Log::Stream stream(LogMessageLevel lml = LML_NORMAL,
bool maskDebug = false);
void setLogDetail(LoggingLevel ll);
static LogManager& getSingleton(void);
static LogManager* getSingletonPtr(void);
};
}
#endif
4:#include "OgreStableHeaders.h"
#include "OgreLogManager.h"
#include "OgreException.h"
#include <algorithm>
namespace Ogre {
template<> LogManager* Singleton<LogManager>::ms_Singleton = 0;
LogManager* LogManager::getSingletonPtr(void)
{
return ms_Singleton;
}
LogManager& LogManager::getSingleton(void)
{
assert( ms_Singleton ); return ( *ms_Singleton );
}
LogManager::LogManager()
{
mDefaultLog = NULL;
}
LogManager::~LogManager()
{
OGRE_LOCK_AUTO_MUTEX
// Destroy all logs
LogList::iterator i;
for (i = mLogs.begin(); i != mLogs.end(); ++i)
{
OGRE_DELETE i->second;
}
}
Log* LogManager::createLog( const String& name, bool defaultLog, bool debuggerOutput,
bool suppressFileOutput)
{
OGRE_LOCK_AUTO_MUTEX
Log* newLog = OGRE_NEW Log(name, debuggerOutput, suppressFileOutput);
if( !mDefaultLog || defaultLog )
{
mDefaultLog = newLog;
}
mLogs.insert( LogList::value_type( name, newLog ) );
return newLog;
}
Log* LogManager::getDefaultLog()
{
OGRE_LOCK_AUTO_MUTEX
return mDefaultLog;
}
Log* LogManager::setDefaultLog(Log* newLog)
{
OGRE_LOCK_AUTO_MUTEX
Log* oldLog = mDefaultLog;
mDefaultLog = newLog;
return oldLog;
}
Log* LogManager::getLog( const String& name)
{
OGRE_LOCK_AUTO_MUTEX
LogList::iterator i = mLogs.find(name);
if (i != mLogs.end())
return i->second;
else
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Log not found. ", "LogManager::getLog");
}
void LogManager::destroyLog(const String& name)
{
LogList::iterator i = mLogs.find(name);
if (i != mLogs.end())
{
if (mDefaultLog == i->second)
{
mDefaultLog = 0;
}
OGRE_DELETE i->second;
mLogs.erase(i);
}
if (!mDefaultLog && !mLogs.empty())
{
mDefaultLog = mLogs.begin()->second;
}
}
void LogManager::destroyLog(Log* log)
{
destroyLog(log->getName());
}
void LogManager::logMessage( const String& message, LogMessageLevel lml, bool maskDebug)
{
OGRE_LOCK_AUTO_MUTEX
if (mDefaultLog)
{
mDefaultLog->logMessage(message, lml, maskDebug);
}
}
void LogManager::setLogDetail(LoggingLevel ll)
{
OGRE_LOCK_AUTO_MUTEX
if (mDefaultLog)
{
mDefaultLog->setLogDetail(ll);
}
}
Log::Stream LogManager::stream(LogMessageLevel lml, bool maskDebug)
{
OGRE_LOCK_AUTO_MUTEX
if (mDefaultLog)
return mDefaultLog->stream(lml, maskDebug);
else
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Default log not found. ", "LogManager::stream");
}
}
4: 部分代码
class myFrameListener : public ExampleFrameListener
{
protected:
SceneNode *pNodeHeadGroup,*pNodeHead1,*pNodeHead2;
public:
myFrameListener(RenderWindow* win, Camera* cam, SceneNode* pNode1,SceneNode* pNode2,SceneNode* pNode3)
: ExampleFrameListener(win, cam)
{
pNodeHeadGroup = pNode1;
pNodeHead1 = pNode2;
pNodeHead2 = pNode3;
}
bool frameStarted(const FrameEvent& evt)
{
pNodeHeadGroup->yaw(evt.timeSinceLastFrame * 30);
pNodeHead1->pitch(evt.timeSinceLastFrame * -360);
pNodeHead2->roll(evt.timeSinceLastFrame * 1440);
return ExampleFrameListener::frameStarted(evt);
}
};
class myApp :public ExampleApplication
{
public:
myApp(){}
protected:
SceneNode *pNodeDragon,*pNodeHeadGroup,*pNodeHead1,*pNodeHead2;
void createScene(void)
{
mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
pNodeDragon = mSceneMgr->getRootSceneNode()->createChild();
Entity *pEntityDragon = mSceneMgr->createEntity("Dragon", "Dragon.mesh");
pNodeDragon->attachObject(pEntityDragon);
pNodeDragon->setScale(0.5,0.5,0.5);
pNodeHeadGroup = mSceneMgr->getRootSceneNode()->createChild();
pNodeHead1 = pNodeHeadGroup->createChild();
pNodeHead1->translate(200,0,0);
Entity *pEntityHead1 = mSceneMgr->createEntity("head1", "ogrehead.mesh");
pNodeHead1->attachObject(pEntityHead1);
pNodeHead2 = pNodeHeadGroup->createChild();
pNodeHead2->translate(-200,0,0);
Entity *pEntityHead2 = pEntityHead1->clone("head2");
pNodeHead2->attachObject(pEntityHead2);
}
void createFrameListener(void)
{
mFrameListener= new myFrameListener(mWindow, mCamera, pNodeHeadGroup,pNodeHead1,pNodeHead2);
mRoot->addFrameListener(mFrameListener);
}
};
- ogre log
- Ogre使用log(一)
- Ogre使用log(二)
- Ogre使用log(三)
- Ogre使用Log(四)
- Ogre中生成内存泄露信息(OgreLeaks.log)的方法
- ogre - Change Log OGRE 1.0.1 至1.8.0版本 更新日志
- Ogre
- ogre
- OGRE
- OGRE
- ogre
- OGRE
- ogre
- 加载场景时,遇到的无法显示场景的问题。遇到问题一定要去看Ogre.log
- log
- log
- log
- 如可访问注册表
- Java和C#运行命令行的例子对比
- C++学习笔记(转)
- 常用验证代码
- sqlserver 2005 交叉表和层次关系查询
- ogre log
- Email 正则表达式
- 全面整理的C++面试题(转载)
- Static长度随文字变化
- dos文件放到linux上面显示^M问题的解决
- C# 中@符号在字符串中的
- smp8635新产品发布
- 1
- vb中从excel中捞取数据插入表中!