MyGUI 3.4.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 <ctime>
11
12namespace MyGUI
13{
14
16 {
17 /*time_t ctTime;
18 time(&ctTime);
19 struct tm *currentTime;
20 currentTime = localtime(&ctTime);*/
21
22 mStream.open(mFileName.c_str(), std::ios_base::out);
23
24 /*log(
25 "Log",
26 LogLevel::Info,
27 currentTime,
28 LogStream()
29 << "Log file created "
30 << std::setw(2) << std::setfill('0') << currentTime->tm_mday << "."
31 << std::setw(2) << std::setfill('0') << (currentTime->tm_mon + 1) << "."
32 << std::setw(2) << std::setfill('0') << (currentTime->tm_year + 1900) <<
33 LogStream::End(),
34 __FILE__, __LINE__);*/
35 }
36
38 {
39 if (mStream.is_open())
40 mStream.close();
41 }
42
44 {
45 if (mStream.is_open())
46 mStream.flush();
47 }
48
49 void FileLogListener::log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line)
50 {
51 if (mStream.is_open())
52 {
53 const char* separator = " | ";
54 mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":"
55 << std::setw(2) << std::setfill('0') << _time->tm_min << ":"
56 << std::setw(2) << std::setfill('0') << _time->tm_sec << separator
57 << _section << separator << _level.print() << separator
58 << _message << separator << _file << separator << _line << std::endl;
59 }
60 }
61
62 void FileLogListener::setFileName(const std::string& _value)
63 {
64 mFileName = _value;
65 }
66
67 const std::string& FileLogListener::getFileName() const
68 {
69 return mFileName;
70 }
71
72} // namespace MyGUI
void setFileName(const std::string &_value)
void log(const std::string &_section, LogLevel _level, const struct tm *_time, const std::string &_message, const char *_file, int _line) override
const std::string & getFileName() const
std::string print() const