52 lines
999 B
C++
52 lines
999 B
C++
#include "log.h"
|
|
#include <cstdio>
|
|
#include <ctime>
|
|
|
|
Logger* Logger::getInstance() {
|
|
return instance_;
|
|
}
|
|
|
|
void Logger::debug(const std::string& s) const {
|
|
_log(LogLevel::Debug, s);
|
|
}
|
|
|
|
void Logger::info(const std::string& s) const {
|
|
_log(LogLevel::Info, s);
|
|
}
|
|
|
|
void Logger::warn(const std::string& s) const {
|
|
_log(LogLevel::Warn, s);
|
|
}
|
|
|
|
void Logger::error(const std::string& s) const {
|
|
_log(LogLevel::Error, s);
|
|
}
|
|
|
|
void Logger::fatal(const std::string& s) const {
|
|
_log(LogLevel::Fatal, s);
|
|
}
|
|
|
|
void Logger::setLogLeval(LogLevel v) {
|
|
filter = v;
|
|
}
|
|
|
|
Logger::Logger() {
|
|
filter = LogLevel::Warn;
|
|
}
|
|
|
|
Logger* const Logger::instance_ = new Logger();
|
|
|
|
void Logger::_log(LogLevel v, const std::string& s) const {
|
|
if (v >= filter) {
|
|
time_t now = time(NULL);
|
|
static char buff[100];
|
|
strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", localtime(&now));
|
|
const char* mp = "DIWEF";
|
|
fprintf(stderr, "%s [%c] %s\n", buff, mp[(int)v], s.c_str());
|
|
}
|
|
}
|
|
|
|
Logger* Log() {
|
|
return Logger::getInstance();
|
|
}
|