-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cpp
More file actions
42 lines (35 loc) · 898 Bytes
/
Logger.cpp
File metadata and controls
42 lines (35 loc) · 898 Bytes
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
#include "Logger.h"
#include "Thread.h"
#include <iostream>
Logger& Logger::getInstance() {
static Logger logger;
return logger;
}
void Logger::setLevel(Level level) {
level_ = level;
}
// [级别信息] 时间戳 : msg
void Logger::log(const std::string& msg) {
std::string pre = "";
switch(level_) {
case Level::INFO:
pre = "[INFO] ";
break;
case Level::DEBUG:
pre = "[DEBUG] ";
break;
case Level::ERROR:
pre = "[ERROR] ";
break;
case Level::FATAL:
pre = "[FATAL] ";
break;
default:
break;
}
time_t now;
time(&now);
std::string timeString(ctime(&now));
timeString = timeString.substr(0, timeString.size() - 1);
std::cout << pre + timeString << " " << gettid() << " : " << msg << std::endl;
}