/
ilogwriter.h
81 lines (69 loc) · 1.75 KB
/
ilogwriter.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
80
81
#pragma once
#include <string>
#include <mutex>
namespace applog
{
enum class LogLevel
{
Verbose = 0,
Standard,
Warning,
Error,
};
constexpr LogLevel AllLogLevels[] = {
LogLevel::Verbose,
LogLevel::Standard,
LogLevel::Warning,
LogLevel::Error
};
/**
* greebo: A LogDevice is a class which is able to take log output.
*
* Examples of LogDevices are the Console and the DarkRadiant logfile.
* Note: Use the LogWriter::attach() method to register a class for logging.
*/
class ILogDevice
{
public:
virtual ~ILogDevice() {}
/**
* greebo: This method gets called by the ILogWriter with
* a log string as argument.
*/
virtual void writeLog(const std::string& outputStr, LogLevel level) = 0;
};
/**
* Central logging hub, dispatching any incoming log messages
* to all attached ILogDevices.
*
* Also offers the stream references to set up the rMessage/rWarning streams
* in every module.
*/
class ILogWriter
{
public:
virtual ~ILogWriter()
{}
/**
* greebo: Writes the given buffer p with the given length to the
* various output devices (i.e. Console and Log file).
*/
virtual void write(const char* p, std::size_t length, LogLevel level) = 0;
/**
* Returns the stream reference for the given log level. These are used
* to initialise the global rMessage/rWarning streams used by the application.
*/
virtual std::ostream& getLogStream(LogLevel level) = 0;
/**
* Returns the synchronization object for writing to the streams.
*/
virtual std::mutex& getStreamLock() = 0;
/**
* greebo: Use these methods to attach/detach a log device from the
* writer class. After attaching a device, all log output
* will be written to it.
*/
virtual void attach(ILogDevice* device) = 0;
virtual void detach(ILogDevice* device) = 0;
};
}