/
LogStreamBuf.h
43 lines (34 loc) · 946 Bytes
/
LogStreamBuf.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
#pragma once
#include "ilogwriter.h"
#include <streambuf>
namespace applog
{
/**
* greebo: The LogStreamBuf adapts the std::streambuf to use to the
* LogWriter class for the actual logging.
*/
class LogStreamBuf :
public std::streambuf
{
// Internal character buffer
char* _reserve;
// The associated level, is passed to the LogWriter
ELogLevel _level;
public:
/**
* greebo: Pass the level and the optional buffersize to the constructor.
* Level can be something like SYS_ERROR, SYS_STANDARD, etc.
*/
LogStreamBuf(ELogLevel level, int bufferSize = 0);
// Cleans up the buffer
virtual ~LogStreamBuf();
protected:
// These two get called by the base class streambuf and are necessary
// in order to write the buffer to the device
virtual int_type overflow(int_type c);
virtual int_type sync();
private:
// Writes the buffer contents to the log device
void writeToBuffer();
};
} // namespace applog