blob: 9aea9584067036f3abe4dbd0436ac5d5e5816d4b (
plain)
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
|
#pragma once
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
class log_stream
{
public:
log_stream();
void log_lines(int n);
std::string get_log();
// log to buffer
void activate();
// log to plain console
void deactivate();
template<typename T>
log_stream& operator<<(const T& arg) {
if (m_active) {
m_buffer << arg;
trim_buffer();
}
else
{
std::cout << arg;
}
return *this;
}
log_stream& operator<<(
std::basic_ostream<char>& (*func)
(std::basic_ostream<char>&) );
private:
void trim_buffer();
bool m_active;
std::stringstream m_buffer;
int m_log_lines;
};
extern log_stream log_cout;
|