forked from tjjh89017/ezio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.cpp
45 lines (32 loc) · 775 Bytes
/
logger.cpp
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
#include "logger.hpp"
std::string Logger::logfile = "ezio.log";
Logger::Logger() {
this->log.open(logfile, std::ios::out);
}
Logger::~Logger() {
// flush out
this->log << this->buffer.str() << std::flush;
this->buffer.str("");
this->log.close();
}
void Logger::setLogFile(std::string name) {
Logger::logfile = name;
}
Logger& Logger::getInstance() {
static Logger instance;
return instance;
}
std::ostream& Logger::info() {
if(this->buffer.tellp() > Logger::MAX_BUFFER) {
this->log << this->buffer.str() << std::flush;
this->buffer.str("");
}
return this->buffer;
}
std::ostream& Logger::debug() {
if(this->buffer.tellp() > Logger::MAX_BUFFER) {
this->log << this->buffer.str() << std::flush;
this->buffer.str("");
}
return this->buffer;
}