-
Notifications
You must be signed in to change notification settings - Fork 22
/
Logging.cpp
85 lines (65 loc) · 1.08 KB
/
Logging.cpp
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
76
77
78
79
80
81
82
83
84
#include "StdAfx.h"
#include "Logging.h"
CLogger g_Logger;
CLogFile::CLogFile()
{
m_File = NULL;
}
CLogFile::~CLogFile()
{
Close();
}
bool CLogFile::Open(const char *filepath)
{
Close();
m_File = fopen(filepath, "wt");
return m_File != NULL;
}
void CLogFile::Close()
{
if (m_File)
{
fclose(m_File);
m_File = NULL;
}
}
void CLogFile::Write(const char *text)
{
if (m_File)
{
fwrite(text, sizeof(char), strlen(text), m_File);
}
}
CLogger::CLogger()
{
}
CLogger::~CLogger()
{
Close();
}
bool CLogger::Open()
{
return m_Log.Open(g_pGlobals->GetGameFile("console.txt").c_str());
}
void CLogger::Close()
{
m_Log.Close();
}
void CLogger::Write(int category, int level, const char *format, ...)
{
va_list args;
va_start(args, format);
int charcount = _vscprintf(format, args) + 1;
char *charbuffer = new char[charcount];
_vsnprintf(charbuffer, charcount, format, args);
#ifdef _DEBUG
OutputDebugStringA(charbuffer);
#endif
m_Log.Write(charbuffer);
for (auto& callback : m_LogCallbacks)
{
callback(category, level, charbuffer);
}
delete[] charbuffer;
va_end(args);
}