-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLogger.cpp
More file actions
34 lines (29 loc) · 768 Bytes
/
Copy pathLogger.cpp
File metadata and controls
34 lines (29 loc) · 768 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
#include "Logger.h"
#include "Timestamp.h"
#include <iostream>
Logger &Logger::instance() {
static Logger logger;
return logger;
}
void Logger::setLogLevel(int level) { logLevel_ = level; }
void Logger::log(std::string msg) {
std::string pre = "";
switch (logLevel_) {
case INFO:
pre = "[INFO] ";
break;
case ERROR:
pre = "[ERROR] ";
break;
case FATAL:
pre = "[FATAL] ";
break;
case DEBUG:
pre = "[DEBUG] ";
break;
default:
break;
}
//!NOTE: 将日志打印由两次改为一次,避免并发时打印错位
std::cout << pre + Timestamp::now().toString() << ": " << msg << std::endl;
}