MyGUI: MyGUI_FileLogListener.cpp Source File

MyGUI 3.2.2

MyGUI_FileLogListener.cpp
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #include "MyGUI_Precompiled.h"
8 #include "MyGUI_FileLogListener.h"
9 #include <iomanip>
10 #include <time.h>
11
12 namespace MyGUI
13 {
14
15 FileLogListener::FileLogListener()
16 {
17 }
18
19 FileLogListener::~FileLogListener()
20 {
21 }
22
23 void FileLogListener::open()
24 {
25 /*time_t ctTime;
26 time(&ctTime);
27 struct tm *currentTime;
28 currentTime = localtime(&ctTime);*/
29
30 mStream.open(mFileName.c_str(), std::ios_base::out);
31
32 /*log(
33 "Log",
34 LogLevel::Info,
35 currentTime,
36 LogStream()
37 << "Log file created "
38 << std::setw(2) << std::setfill('0') << currentTime->tm_mday << "."
39 << std::setw(2) << std::setfill('0') << (currentTime->tm_mon + 1) << "."
40 << std::setw(2) << std::setfill('0') << (currentTime->tm_year + 1900) <<
41 LogStream::End(),
42 __FILE__, __LINE__);*/
43 }
44
45 void FileLogListener::close()
46 {
47 if (mStream.is_open())
48 mStream.close();
49 }
50
51 void FileLogListener::flush()
52 {
53 if (mStream.is_open())
54 mStream.flush();
55 }
56
57 void FileLogListener::log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line)
58 {
59 if (mStream.is_open())
60 {
61 const char* separator = " | ";
62 mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":"
63 << std::setw(2) << std::setfill('0') << _time->tm_min << ":"
64 << std::setw(2) << std::setfill('0') << _time->tm_sec << separator
65 << _section << separator << _level.print() << separator
66 << _message << separator << _file << separator << _line << std::endl;
67 }
68 }
69
70 void FileLogListener::setFileName(const std::string& _value)
71 {
72 mFileName = _value;
73 }
74
75 const std::string& FileLogListener::getFileName() const
76 {
77 return mFileName;
78 }
79
80 } // namespace MyGUI
MyGUI::FileLogListener::setFileName
void setFileName(const std::string &_value)
Definition: MyGUI_FileLogListener.cpp:70
MyGUI::LogLevel::print
std::string print() const
Definition: MyGUI_LogLevel.h:95
MyGUI::FileLogListener::~FileLogListener
virtual ~FileLogListener()
Definition: MyGUI_FileLogListener.cpp:19
MyGUI::FileLogListener::flush
virtual void flush()
Definition: MyGUI_FileLogListener.cpp:51
MyGUI_Precompiled.h
MyGUI::FileLogListener::open
virtual void open()
Definition: MyGUI_FileLogListener.cpp:23
MyGUI::FileLogListener::getFileName
const std::string & getFileName() const
Definition: MyGUI_FileLogListener.cpp:75
MyGUI::FileLogListener::FileLogListener
FileLogListener()
Definition: MyGUI_FileLogListener.cpp:15
MyGUI_FileLogListener.h
MyGUI::FileLogListener::close
virtual void close()
Definition: MyGUI_FileLogListener.cpp:45
MyGUI::FileLogListener::log
virtual void log(const std::string &_section, LogLevel _level, const struct tm *_time, const std::string &_message, const char *_file, int _line)
Definition: MyGUI_FileLogListener.cpp:57
MyGUI::LogLevel
Definition: MyGUI_LogLevel.h:15
MyGUI
Definition: MyGUI_ActionController.h:14