forked from amhndu/SimpleNES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.cpp
77 lines (64 loc) · 1.34 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
#include "Log.h"
namespace sn
{
Log::~Log()
{
}
Log& Log::get()
{
static Log instance;
return instance;
}
std::ostream& Log::getCpuTraceStream()
{
return *m_cpuTrace;
}
std::ostream& Log::getStream()
{
return *m_logStream;
}
void Log::setLogStream(std::ostream& stream)
{
m_logStream = &stream;
}
void Log::setCpuTraceStream(std::ostream& stream)
{
m_cpuTrace = &stream;
}
Log& Log::setLevel(Level level)
{
m_logLevel = level;
return *this;
}
Level Log::getLevel()
{
return m_logLevel;
}
TeeBuf::TeeBuf(std::streambuf * sb1, std::streambuf * sb2) :
m_sb1(sb1),
m_sb2(sb2)
{}
int TeeBuf::overflow(int c)
{
if (c == EOF)
{
return !EOF;
}
else
{
int const r1 = m_sb1->sputc(c);
int const r2 = m_sb2->sputc(c);
return r1 == EOF || r2 == EOF ? EOF : c;
}
}
int TeeBuf::sync()
{
int const r1 = m_sb1->pubsync();
int const r2 = m_sb2->pubsync();
return r1 == 0 && r2 == 0 ? 0 : -1;
}
TeeStream::TeeStream(std::ostream& o1, std::ostream& o2) :
std::ostream(&m_tbuf),
m_tbuf(o1.rdbuf(), o2.rdbuf())
{}
}