-
Notifications
You must be signed in to change notification settings - Fork 1
/
Log.cpp
executable file
·50 lines (39 loc) · 1 KB
/
Log.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
#include "StdAfx.h"
#include ".\log.h"
static CCriticalSection lockObject;
static CString logString;
Log::Log(void)
{
}
Log::~Log(void)
{
}
void Log::LogUsage(LPCTSTR usage, ...)
{
CString log;
try {
va_list args;
va_start(args, usage);
CString s;
s.FormatV(usage, args);
va_end(args);
static DWORD firstUseTickCount = ::GetTickCount();
static DWORD lastUseTickCount = ::GetTickCount();
DWORD time = ::GetTickCount() - firstUseTickCount;
DWORD timeDelta = lastUseTickCount - lastUseTickCount;
lastUseTickCount = time;
log.Format(_T("%u (%u): %s\r\n"), time/1000, timeDelta, s);
} catch(...) {
log = "Exception in Log::LogUsage()\r\n";
}
CSingleLock lock(&lockObject, TRUE);
logString += log;
return;
}
CString Log::GetUsageString()
{
CSingleLock lock(&lockObject, TRUE);
CString copy = static_cast<LPCTSTR>(logString);
ASSERT(logString.GetLength() == 0 || copy.GetString() != logString.GetString());
return copy;
}