forked from amhndu/SimpleNES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.h
79 lines (70 loc) · 1.92 KB
/
Log.h
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
#ifndef LOG_H
#define LOG_H
#include <iostream>
#include <string>
#include <fstream>
#include <memory>
#include <cstring>
#ifndef __FILENAME__
#define __FILENAME__ __FILE__
#endif
#define LOG(level) \
if (level > sn::Log::get().getLevel()) ; \
else sn::Log::get().getStream() << '[' << __FILENAME__ << ":" << std::dec << __LINE__ << "] "
#define LOG_CPU \
if (sn::CpuTrace != sn::Log::get().getLevel()) ; \
else sn::Log::get().getCpuTraceStream()
namespace sn
{
enum Level
{
None,
Error,
Info,
InfoVerbose,
CpuTrace
};
class Log
{
public:
~Log();
void setLogStream(std::ostream& stream);
void setCpuTraceStream(std::ostream& stream);
Log& setLevel(Level level);
Level getLevel();
std::ostream& getStream();
std::ostream& getCpuTraceStream();
static Log& get();
private:
Level m_logLevel;
std::ostream* m_logStream;
std::ostream* m_cpuTrace;
};
//Courtesy of http://wordaligned.org/articles/cpp-streambufs#toctee-streams
class TeeBuf : public std::streambuf
{
public:
// Construct a streambuf which tees output to both input
// streambufs.
TeeBuf(std::streambuf* sb1, std::streambuf* sb2);
private:
// This tee buffer has no buffer. So every character "overflows"
// and can be put directly into the teed buffers.
virtual int overflow(int c);
// Sync both teed buffers.
virtual int sync();
private:
std::streambuf* m_sb1;
std::streambuf* m_sb2;
};
class TeeStream : public std::ostream
{
public:
// Construct an ostream which tees output to the supplied
// ostreams.
TeeStream(std::ostream& o1, std::ostream& o2);
private:
TeeBuf m_tbuf;
};
};
#endif // LOG_H