23 unsigned int Logger::currentLogLevel = DEBUG;
24 std::vector<LogHandler*> Logger::logHandlers;
26 void Logger::logDebug(
string msg) {
30 void Logger::logWarning(
string msg) {
34 void Logger::logError(
string msg) {
38 void Logger::logInfo(
string msg) {
42 void Logger::log(
unsigned int level,
string msg) {
43 if (level >= currentLogLevel) {
44 for (
auto logHandler : logHandlers) {
46 ss << levelToString(level) <<
"\t" << getTime().c_str() <<
"\t" << msg.c_str() <<
"\n";
47 logHandler->log(ss.str());
52 void Logger::addLogHandler(
LogHandler *logHandler) {
53 logHandlers.push_back(logHandler);
56 void Logger::setLogLevel(
unsigned int level) {
57 currentLogLevel = level;
60 string Logger::levelToString(
unsigned int level) {
62 case INFO:
return "INFO";
63 case DEBUG:
return "DEBUG";
64 case WARNING:
return "WARNING";
65 case SEVERE:
return "SEVERE";
66 default:
return "BAD level";
70 string Logger::getTime() {
74 tstruct = *localtime(&now);
75 strftime(buf,
sizeof(buf),
"%Y-%m-%d.%X", &tstruct);