-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cpp
78 lines (59 loc) · 1.76 KB
/
Logger.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
#include <atltime.h>
#include <Windows.h>
#include <iostream>
#include "Ex\Ex.h"
#include "Ex\Logger.h"
#include "Ex\MessageBoxLogger.h"
Ex::Logger* Ex::Logger::s_pDefaultLogger = 0;
Ex::Logger::Logger()
{
}
Ex::Logger::~Logger()
{
}
void Ex::Logger::DtorResetDefaultLogger()
{
if ( this == s_pDefaultLogger )
{
s_pDefaultLogger = NULL;
}
}
void Ex::Logger::Log( const std::string& message )
{
EX_PRECONDITION( message.size() > 0 );
std::string formattedMessage = FormatMessage( message );
LogFormattedMessage( formattedMessage );
}
Ex::Logger& Ex::Logger::GetDefaultLogger()
{
static MessageBoxLogger* s_pMessageBoxLogger = new MessageBoxLogger();
if ( s_pDefaultLogger == NULL )
{
s_pDefaultLogger = s_pMessageBoxLogger;
}
return *s_pDefaultLogger;
}
Ex::Logger& Ex::Logger::SetDefaultLogger( Logger& newDefaultLogger )
{
Logger& defaultLogger = GetDefaultLogger();
s_pDefaultLogger = &newDefaultLogger;
return defaultLogger;
}
std::string Ex::Logger::FormatMessage( const std::string& message )
{
CTime time( CTime::GetCurrentTime() );
tm gmtTime = *( time.GetGmtTm() );
std::stringstream formattedMessageStream;
if ( Ex::Exception::GetVariableData() )
{
formattedMessageStream << gmtTime.tm_mday << "/" << gmtTime.tm_mon << "/" << gmtTime.tm_year + 1900 << " "
<< gmtTime.tm_hour << ":" << gmtTime.tm_min << ":" << gmtTime.tm_sec << " gmt - "
<< message;
}
else
{
formattedMessageStream << "<date and time suppressed>" << " - "
<< message;
}
return formattedMessageStream.str();
}