-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.hpp
83 lines (64 loc) · 2.03 KB
/
logger.hpp
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
82
83
#ifndef _LOGGER_HPP_
#define _LOGGER_HPP_
#include <iostream>
#include <mutex>
#include <string>
#include <vector>
#include <thread>
#include "config.hpp"
#define QUOTE(x) #x
#define STR(x) QUOTE(x)
#define LOC() "[" __FILE__ ":" STR(__LINE__) "] "
#define TODO throw std::runtime_error(LOC() "Not Implemented")
#ifdef DEBUG
#define DEBUG_STREAM std::cerr
#else
// I'm sorry
#define DEBUG_STREAM *(new std::ostream(new NullBuffer()))
#endif
namespace logs
{
class log_line
{
protected:
log_line(std::ostream& pConsole);
static std::vector<std::ostream*> streams;
static std::mutex mutex;
std::ostream& mConsole;
public:
static void register_stream(std::ostream* pTarget);
static void register_streams(std::vector<std::ostream*> pTargets);
template <typename T>
friend log_line& operator<< (log_line& pLogLine, T pValue);
friend log_line& operator<< (log_line& pLogLine, log_line& (&pf)(log_line&));
friend log_line& operator<< (log_line& pLogLine, std::ostream& (&pf)(std::ostream&));
friend log_line& done(log_line& pLogLine);
friend log_line& endl(log_line& pLogLine);
};
class logger : public log_line
{
protected:
char const* mLevelName;
unsigned char mStatusCode;
public:
logger(std::ostream& pConsole, unsigned char pStatusCode, const char* pLevelName);
template <typename T>
friend log_line& operator<< (logger& pLogger, T pValue);
friend log_line& operator<< (logger& pLogger, log_line& (&pf)(log_line&));
friend log_line& operator<< (logger& pLogger, std::ostream& (&pf)(std::ostream&));
};
class NullBuffer : public std::streambuf
{
public:
int overflow(int c)
{
return c;
}
};
extern log_line& done(log_line& pLogLine);
extern log_line& endl(log_line& pLogLine);
extern logger fatal, error, warn, info, debug;
}
#include "thread.hpp"
#include "logger.ipp"
#endif /*LOGGER_HPP*/