-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlogger.cc
More file actions
39 lines (30 loc) · 748 Bytes
/
logger.cc
File metadata and controls
39 lines (30 loc) · 748 Bytes
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
#include "logger.h"
#include <iostream>
namespace Logger { namespace Detail {
static std::vector<char> gBuffer;
// naive implemntation, for demonstration purposes only
char* GetWriteBuffer(int size)
{
size_t offset = gBuffer.size();
gBuffer.resize(gBuffer.size() + size);
return gBuffer.data() + offset;
}
const char* ConsumeRecord(const char* data)
{
const Header* header = reinterpret_cast<const Header*>(data);
const char* args = data + sizeof(Header);
header->Formatter(std::cout, header->FormatString, args);
return args + header->ArgsSize;
}
}
void Consume()
{
const char* d = Detail::gBuffer.data();
const char* end = d + Detail::gBuffer.size();
while(d < end)
{
d = Detail::ConsumeRecord(d);
}
assert(d == end);
}
}