MyGUI 3.5.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"
10#include <iomanip>
11#include <ctime>
12
13namespace MyGUI
14{
15
16 void FileLogListener::open()
17 {
18 mStream.open(utility::toPath(mFileName), std::ios_base::out);
19 }
20
21 void FileLogListener::close()
22 {
23 if (mStream.is_open())
24 mStream.close();
25 }
26
27 void FileLogListener::flush()
28 {
29 if (mStream.is_open())
30 mStream.flush();
31 }
32
33 void FileLogListener::log(
34 std::string_view _section,
35 LogLevel _level,
36 const struct tm* _time,
37 std::string_view _message,
38 std::string_view _file,
39 int _line)
40 {
41 if (mStream.is_open())
42 {
43 std::string_view separator = " | ";
44 mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":" << std::setw(2) << std::setfill('0')
45 << _time->tm_min << ":" << std::setw(2) << std::setfill('0') << _time->tm_sec << separator
46 << _section << separator << _level.print() << separator << _message << separator << _file
47 << separator << _line << std::endl;
48 }
49 }
50
51 void FileLogListener::setFileName(std::string_view _value)
52 {
53 mFileName = _value;
54 }
55
56 const std::string& FileLogListener::getFileName() const
57 {
58 return mFileName;
59 }
60
61} // namespace MyGUI
std::filesystem::path toPath(std::string_view text)
Convert UTF-8 bytes to a native filesystem path.