MyGUI: MyGUI_FileLogListener.cpp Source File

MyGUI 3.4.3

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 <ctime>
11
12namespace MyGUI
13{
14
15 void FileLogListener::open()
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
37 void FileLogListener::close()
38 {
39 if (mStream.is_open())
40 mStream.close();
41 }
42
43 void FileLogListener::flush()
44 {
45 if (mStream.is_open())
46 mStream.flush();
47 }
48
49 void FileLogListener::log(
50 std::string_view _section,
51 LogLevel _level,
52 const struct tm* _time,
53 std::string_view _message,
54 std::string_view _file,
55 int _line)
56 {
57 if (mStream.is_open())
58 {
59 std::string_view separator = " | ";
60 mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":" << std::setw(2) << std::setfill('0')
61 << _time->tm_min << ":" << std::setw(2) << std::setfill('0') << _time->tm_sec << separator
62 << _section << separator << _level.print() << separator << _message << separator << _file
63 << separator << _line << std::endl;
64 }
65 }
66
67 void FileLogListener::setFileName(std::string_view _value)
68 {
69 mFileName = _value;
70 }
71
72 const std::string& FileLogListener::getFileName() const
73 {
74 return mFileName;
75 }
76
77} // namespace MyGUI
MyGUI_FileLogListener.h
MyGUI_Precompiled.h
MyGUI::FileLogListener::setFileName
void setFileName(std::string_view _value)
Definition MyGUI_FileLogListener.cpp:67
MyGUI::FileLogListener::flush
void flush() override
Definition MyGUI_FileLogListener.cpp:43
MyGUI::FileLogListener::log
void log(std::string_view _section, LogLevel _level, const struct tm *_time, std::string_view _message, std::string_view _file, int _line) override
Definition MyGUI_FileLogListener.cpp:49
MyGUI::FileLogListener::open
void open() override
Definition MyGUI_FileLogListener.cpp:15
MyGUI::FileLogListener::close
void close() override
Definition MyGUI_FileLogListener.cpp:37
MyGUI::FileLogListener::getFileName
const std::string & getFileName() const
Definition MyGUI_FileLogListener.cpp:72
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::LogLevel
Definition MyGUI_LogLevel.h:19
MyGUI::LogLevel::print
std::string_view print() const
Definition MyGUI_LogLevel.h:98