OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
myguiloglistener.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_MYGUIPLATFORM_LOGLISTENER_H
2 #define OPENMW_COMPONENTS_MYGUIPLATFORM_LOGLISTENER_H
3 
4 #include <string>
5 #include <boost/filesystem/fstream.hpp>
6 
7 #include <MyGUI_ILogListener.h>
8 #include <MyGUI_LogSource.h>
9 #include <MyGUI_ConsoleLogListener.h>
10 #include <MyGUI_LevelLogFilter.h>
11 
12 namespace osgMyGUI
13 {
14 
18  class CustomLogListener : public MyGUI::ILogListener
19  {
20  public:
21  CustomLogListener(const std::string &name)
22  : mFileName(name)
23  {}
24 
26 
27  virtual void open();
28  virtual void close();
29  virtual void flush();
30 
31  virtual void log(const std::string& _section, MyGUI::LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line);
32 
33  const std::string& getFileName() const { return mFileName; }
34 
35  private:
36  boost::filesystem::ofstream mStream;
37  std::string mFileName;
38  };
39 
43  {
44  MyGUI::ConsoleLogListener mConsole;
46  MyGUI::LevelLogFilter mFilter;
47  MyGUI::LogSource mSource;
48 
49  public:
50 
51  LogFacility(const std::string &output, bool console)
52  : mFile(output)
53  {
54  mConsole.setEnabled(console);
55  mFilter.setLoggingLevel(MyGUI::LogLevel::Info);
56 
57  mSource.addLogListener(&mFile);
58  mSource.addLogListener(&mConsole);
59  mSource.setLogFilter(&mFilter);
60 
61  mSource.open();
62  }
63 
64  MyGUI::LogSource *getSource() { return &mSource; }
65  };
66 
67 }
68 
69 #endif
const std::string & getFileName() const
Definition: myguiloglistener.hpp:33
boost::filesystem::ofstream mStream
Definition: myguiloglistener.hpp:36
Custom MyGUI::ILogListener interface implementation being able to portably handle UTF-8 encoded path...
Definition: myguiloglistener.hpp:18
~CustomLogListener()
Definition: myguiloglistener.hpp:25
CustomLogListener(const std::string &name)
Definition: myguiloglistener.hpp:21
LogFacility(const std::string &output, bool console)
Definition: myguiloglistener.hpp:51
MyGUI::LevelLogFilter mFilter
Definition: myguiloglistener.hpp:46
virtual void flush()
Definition: myguiloglistener.cpp:21
virtual void log(const std::string &_section, MyGUI::LogLevel _level, const struct tm *_time, const std::string &_message, const char *_file, int _line)
Definition: myguiloglistener.cpp:27
std::string mFileName
Definition: myguiloglistener.hpp:37
CustomLogListener mFile
Definition: myguiloglistener.hpp:45
MyGUI::LogSource * getSource()
Definition: myguiloglistener.hpp:64
Helper class holding data that required during MyGUI log creation.
Definition: myguiloglistener.hpp:42
MyGUI::ConsoleLogListener mConsole
Definition: myguiloglistener.hpp:44
virtual void open()
Definition: myguiloglistener.cpp:10
MyGUI::LogSource mSource
Definition: myguiloglistener.hpp:47
virtual void close()
Definition: myguiloglistener.cpp:15
const char * name
Definition: crashcatcher.cpp:59