-
Notifications
You must be signed in to change notification settings - Fork 4
/
logging.cpp
36 lines (29 loc) · 1 KB
/
logging.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
#include "logging.hpp"
// Defined in header: enum TLogLevel{ logCRITICAL , logERROR , logWARNING , logINFO , logINFO2, logDEBUG , logDEBUG1 , logDEBUG2 , logDEBUG3 , logDEBUG4 };
const char *TLogLevelToString[10] = {"logCRITICAL", "logERROR", "logWARNING", "logINFO", "logINFO2", "logDEBUG", "logDEBUG1", "logDEBUG2", "logDEBUG3", "logDEBUG4"};
static TLogLevel globalMessageLevel = logINFO2;
char *
nowtime(char *buffer) {
time_t rawtime;
time(&rawtime);
struct tm t;
localtime_r(&rawtime, &t);
strftime(buffer, 128, "%F %T %z", &t);
return buffer;
}
TLogLevel& Log::ReportingLevel() { return globalMessageLevel; };
std::ostringstream&
Log::Get(TLogLevel level) {
char buffer[128];
os << "- " << nowtime(buffer);
os << " " << TLogLevelToString[level] << ": ";
messageLevel = level;
return os;
}
Log::~Log() {
if (messageLevel <= Log::ReportingLevel()) {
os << std::endl;
fprintf(stderr, "%s", os.str().c_str());
fflush(stderr);
}
}