forked from teamnwah/openmw-tes3coop
OpenEngine MyGUI logging facility
This commit is contained in:
parent
a46662043a
commit
46c32f6c47
5 changed files with 111 additions and 5 deletions
|
@ -129,6 +129,7 @@ set(OENGINE_OGRE
|
|||
)
|
||||
|
||||
set(OENGINE_GUI
|
||||
${LIBDIR}/openengine/gui/loglistener.cpp
|
||||
${LIBDIR}/openengine/gui/manager.cpp
|
||||
${LIBDIR}/openengine/gui/layout.hpp
|
||||
)
|
||||
|
|
39
libs/openengine/gui/loglistener.cpp
Normal file
39
libs/openengine/gui/loglistener.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "loglistener.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <time.h>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
void CustomLogListener::open()
|
||||
{
|
||||
mStream.open(boost::filesystem::path(mFileName), std::ios_base::out);
|
||||
}
|
||||
|
||||
void CustomLogListener::close()
|
||||
{
|
||||
if (mStream.is_open())
|
||||
mStream.close();
|
||||
}
|
||||
|
||||
void CustomLogListener::flush()
|
||||
{
|
||||
if (mStream.is_open())
|
||||
mStream.flush();
|
||||
}
|
||||
|
||||
void CustomLogListener::log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line)
|
||||
{
|
||||
if (mStream.is_open())
|
||||
{
|
||||
const char* separator = " | ";
|
||||
mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":"
|
||||
<< std::setw(2) << std::setfill('0') << _time->tm_min << ":"
|
||||
<< std::setw(2) << std::setfill('0') << _time->tm_sec << separator
|
||||
<< _section << separator << _level.print() << separator
|
||||
<< _message << separator << _file << separator << _line << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
35
libs/openengine/gui/loglistener.hpp
Normal file
35
libs/openengine/gui/loglistener.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef OPENENGINE_MYGUI_LOGLISTENER_H
|
||||
#define OPENENGINE_MYGUI_LOGLISTENER_H
|
||||
|
||||
#include <string>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include <MyGUI_ILogListener.h>
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
class CustomLogListener : public ILogListener
|
||||
{
|
||||
public:
|
||||
CustomLogListener(const std::string &name)
|
||||
: mFileName(name)
|
||||
{}
|
||||
|
||||
~CustomLogListener() {}
|
||||
|
||||
virtual void open();
|
||||
virtual void close();
|
||||
virtual void flush();
|
||||
|
||||
virtual void log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line);
|
||||
|
||||
const std::string& getFileName() const { return mFileName; }
|
||||
|
||||
private:
|
||||
boost::filesystem::ofstream mStream;
|
||||
std::string mFileName;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,9 +1,14 @@
|
|||
#include "manager.hpp"
|
||||
#include "loglistener.hpp"
|
||||
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_OgrePlatform.h>
|
||||
#include <MyGUI_Timer.h>
|
||||
|
||||
#include <MyGUI_LevelLogFilter.h>
|
||||
#include <MyGUI_LogSource.h>
|
||||
#include <MyGUI_ConsoleLogListener.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <extern/shiny/Main/Factory.hpp>
|
||||
|
@ -554,8 +559,32 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
}
|
||||
class LogFacility
|
||||
{
|
||||
ConsoleLogListener mConsole;
|
||||
CustomLogListener mFile;
|
||||
LevelLogFilter mFilter;
|
||||
LogSource mSource;
|
||||
|
||||
public:
|
||||
|
||||
LogFacility(const std::string &output, bool console)
|
||||
: mFile(output)
|
||||
{
|
||||
mConsole.setEnabled(console);
|
||||
mFilter.setLoggingLevel(LogLevel::Info);
|
||||
|
||||
mSource.addLogListener(&mFile);
|
||||
mSource.addLogListener(&mConsole);
|
||||
mSource.setLogFilter(&mFilter);
|
||||
|
||||
mSource.open();
|
||||
}
|
||||
|
||||
LogSource *getSource() { return &mSource; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging, const std::string& logDir)
|
||||
{
|
||||
|
@ -586,10 +615,8 @@ void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool
|
|||
mRenderManager = new MyGUI::OgreRenderManager();
|
||||
mDataManager = new MyGUI::FixedOgreDataManager();
|
||||
|
||||
LogManager::getInstance().setSTDOutputEnabled(logging);
|
||||
|
||||
if (!theLogFile.empty())
|
||||
LogManager::getInstance().createDefaultSource(theLogFile);
|
||||
mLogFacility = new MyGUI::LogFacility(theLogFile, logging);
|
||||
LogManager::getInstance().addLogSource(mLogFacility->getSource());
|
||||
|
||||
if (mShaderRenderManager)
|
||||
mShaderRenderManager->initialise(wnd, mgr);
|
||||
|
@ -648,5 +675,7 @@ void MyGUIManager::shutdown()
|
|||
delete mLogManager;
|
||||
mLogManager = NULL;
|
||||
}
|
||||
delete mLogFacility;
|
||||
|
||||
mGui = NULL;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace MyGUI
|
|||
class OgreDataManager;
|
||||
class OgreRenderManager;
|
||||
class ShaderBasedRenderManager;
|
||||
class LogFacility;
|
||||
}
|
||||
|
||||
namespace Ogre
|
||||
|
@ -25,6 +26,7 @@ namespace GUI
|
|||
{
|
||||
MyGUI::Gui *mGui;
|
||||
MyGUI::LogManager* mLogManager;
|
||||
MyGUI::LogFacility* mLogFacility;
|
||||
MyGUI::OgreDataManager* mDataManager;
|
||||
MyGUI::OgreRenderManager* mRenderManager;
|
||||
MyGUI::ShaderBasedRenderManager* mShaderRenderManager;
|
||||
|
|
Loading…
Reference in a new issue