Add Log::colorCodeMessage() helper.

This commit is contained in:
Atgeirr Flø Rasmussen 2016-05-09 11:29:11 +02:00
parent de87c5a5b5
commit 9a03758e9f
2 changed files with 25 additions and 0 deletions

View File

@ -72,5 +72,29 @@ namespace Log {
return prefix + ": " + message;
}
std::string colorCodeMessage(int64_t messageType, const std::string& message) {
std::string colorcode;
switch (messageType) {
case MessageType::Debug:
case MessageType::Info:
colorcode = "\033[39m";
break;
case MessageType::Warning:
colorcode = "\033[33;1m";
break;
case MessageType::Error:
case MessageType::Problem:
case MessageType::Bug:
colorcode = "\033[31;1m";
break;
default:
throw std::invalid_argument("Unhandled messagetype");
}
return colorcode + message + "\033[0m";
}
}
}

View File

@ -40,6 +40,7 @@ namespace Log {
std::string fileMessage(const std::string& path, int line , const std::string& msg);
std::string fileMessage(int64_t messageType , const std::string& path, int line , const std::string& msg);
std::string prefixMessage(int64_t messageType , const std::string& msg);
std::string colorCodeMessage(int64_t messageType , const std::string& msg);
}
}