-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.cpp
80 lines (69 loc) · 1.5 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
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
#include "log.h"
LogManager::LogManager()
{
m_log.Start();
}
LogManager::~LogManager()
{
m_log.Stop();
}
void LogManager::Append(const char * data, size_t writeSize)
{
m_log.Append(data, writeSize);
}
static inline void WriteLogImpl(const char * data, size_t writeSize)
{
Singleton<LogManager>::GetInstance().Append(data, writeSize);
}
void ERRLOGImpl(const char * errMsg)
{
char buff[1024];
memcpy(buff, "ERROR: ", 7);
size_t writeSize = 7;
size_t nErrmsg = strlen(errMsg);
memcpy(buff + writeSize, errMsg, nErrmsg);
writeSize += nErrmsg;
// FIX ME may overflow
buff[writeSize] = '\n';
writeSize += 1;
WriteLogImpl(buff, writeSize);
}
void DEBUGLOGImpl(const char * debugMsg)
{
char buff[1024];
memcpy(buff, "DEBUG: ", 7);
size_t writeSize = 7;
size_t nErrmsg = strlen(debugMsg);
memcpy(buff + writeSize, debugMsg, nErrmsg);
writeSize += nErrmsg;
// FIX ME may overflow
buff[writeSize] = '\n';
writeSize += 1;
WriteLogImpl(buff, writeSize);
}
void ERRLOG(const char * format, ...)
{
char buff[1024];
memset(buff, 0, sizeof(buff));
int nWrite = 0;
va_list ap;
va_start(ap, format);
if (0 < (nWrite = vsnprintf(buff, sizeof(buff), format, ap)))
{
ERRLOGImpl(static_cast<const char *> (buff));
}
va_end(ap);
}
void DEBUGLOG(const char * format, ...)
{
char buff[1024];
memset(buff, 0, sizeof(buff));
int nWrite = 0;
va_list ap;
va_start(ap, format);
if (0 < (nWrite = vsnprintf(buff, sizeof(buff), format, ap)))
{
DEBUGLOGImpl(static_cast<const char *> (buff));
}
va_end(ap);
}