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"
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
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
void setFileName(std::string_view _value)
void log(std::string_view _section, LogLevel _level, const struct tm *_time, std::string_view _message, std::string_view _file, int _line) override
const std::string & getFileName() const
std::string_view print() const