-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathLogger.cpp
More file actions
75 lines (64 loc) · 1.5 KB
/
Logger.cpp
File metadata and controls
75 lines (64 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "StdAfx.h"
#include "Logger.h"
namespace Debug
{
void Logger::Open(CStringW filename)
{
this->Close();
//USES_CONVERSION;
const CStringW path = Utility::GetFolderFromPath(filename);
if (!Utility::DirExists(path))
_wmkdir(path);
m_logger.open(filename);
m_filename = filename;
Debug::WriteLine("Log opened: %d", m_logger.is_open());
Debug::WriteLine("Log bad: %d", m_logger.bad());
Debug::WriteLine("Log fail: %d", m_logger.fail());
Debug::WriteLine("Log good: %d", m_logger.good());
Debug::WriteLine("Log eof: %d", m_logger.eof());
}
bool Logger::IsOpened()
{
return m_logger.is_open() && m_logger.good();
}
void Logger::WriteLine(CString format, ...)
{
if (IsOpened() || Debug::IsDebugMode())
{
TCHAR buffer[1024];
va_list args;
va_start( args, format);
vsprintf( buffer, format, args );
CString s = buffer;
if (format.GetLength() > 0)
{
SYSTEMTIME time;
GetLocalTime(&time);
CString s2;
s2.Format("%02d:%02d:%02d.%-3d: ", time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
m_logger << s2 << s << endl;
Debug::WriteWithThreadId(s2 + s, DebugTiles);
}
else {
m_logger << endl;
}
m_logger.flush();
}
}
CStringW Logger::GetFilename()
{
return m_filename;
}
void Logger::Close()
{
if (m_logger.is_open())
{
m_logger.flush();
m_logger.close();
}
}
void Logger::Log(CString message)
{
WriteLine(message);
}
}