-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cpp
More file actions
75 lines (65 loc) · 1.7 KB
/
Logger.cpp
File metadata and controls
75 lines (65 loc) · 1.7 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
// Logger.cpp: implementation of the CLogger class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Logger.h"
#include "BWUtil.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLogger* CLogger::m_inst = NULL;
CLogger::CLogger()
{
if (1)
{
m_file = CreateFile("apmalertlog.txt",GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (m_file == INVALID_HANDLE_VALUE)
m_file = CreateFile("apmalertlog.txt",GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
}
}
CLogger::~CLogger()
{
if (m_file != NULL)
CloseHandle(m_file);
}
CLogger* CLogger::getinstance()
{
if (m_inst == NULL)
m_inst = new CLogger();
return m_inst;
}
void CLogger::log1(std::string msg)
{
if (m_file == INVALID_HANDLE_VALUE)
return;
DWORD wed = 0;
msg = msg + "\n";
DWORD len = strlen(msg.c_str());
WriteFile(m_file, msg.c_str(), len, &wed, NULL);
}
void CLogger::log(const char* fmt, ...)
{
if (m_file == INVALID_HANDLE_VALUE)
return;
char buf[1024];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
log1(buf);
//printf()
}
void CLogger::screenlog(const char* fmt, ...)
{
char buf[1024];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
BWDrawText(20, 20, buf);
}