mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
C++
69 lines
1.8 KiB
C++
#ifndef OPENMW_COMPONENTS_MYGUIPLATFORM_LOGLISTENER_H
|
|
#define OPENMW_COMPONENTS_MYGUIPLATFORM_LOGLISTENER_H
|
|
|
|
#include <string>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
#include <MyGUI_ILogListener.h>
|
|
#include <MyGUI_LogSource.h>
|
|
#include <MyGUI_ConsoleLogListener.h>
|
|
#include <MyGUI_LevelLogFilter.h>
|
|
|
|
namespace osgMyGUI
|
|
{
|
|
|
|
/// \brief Custom MyGUI::ILogListener interface implementation
|
|
/// being able to portably handle UTF-8 encoded path.
|
|
/// \todo try patching MyGUI to make this easier
|
|
class CustomLogListener : public MyGUI::ILogListener
|
|
{
|
|
public:
|
|
CustomLogListener(const std::filesystem::path &name)
|
|
: mFileName(name)
|
|
{}
|
|
|
|
~CustomLogListener() {}
|
|
|
|
void open() override;
|
|
void close() override;
|
|
void flush() override;
|
|
|
|
void log(const std::string& _section, MyGUI::LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line) override;
|
|
|
|
private:
|
|
std::ofstream mStream;
|
|
std::filesystem::path mFileName;
|
|
};
|
|
|
|
/// \brief Helper class holding data that required during
|
|
/// MyGUI log creation
|
|
class LogFacility
|
|
{
|
|
MyGUI::ConsoleLogListener mConsole;
|
|
CustomLogListener mFile;
|
|
MyGUI::LevelLogFilter mFilter;
|
|
MyGUI::LogSource mSource;
|
|
|
|
public:
|
|
|
|
LogFacility(const std::filesystem::path &output, bool console)
|
|
: mFile(output)
|
|
{
|
|
mConsole.setEnabled(console);
|
|
mFilter.setLoggingLevel(MyGUI::LogLevel::Info);
|
|
|
|
mSource.addLogListener(&mFile);
|
|
mSource.addLogListener(&mConsole);
|
|
mSource.setLogFilter(&mFilter);
|
|
|
|
mSource.open();
|
|
}
|
|
|
|
MyGUI::LogSource *getSource() { return &mSource; }
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|