MyGUI  3.2.1
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"
9 #include <iomanip>
10 #include <time.h>
11 
12 namespace MyGUI
13 {
14 
16  {
17  }
18 
20  {
21  }
22 
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 
46  {
47  if (mStream.is_open())
48  mStream.close();
49  }
50 
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