make logs look fancier

This commit is contained in:
ConfiG 2024-01-25 20:45:29 +03:00
parent 777f81d85a
commit f7980d32ab
No known key found for this signature in database
GPG key ID: 44DA1983F524C11B
2 changed files with 15 additions and 7 deletions
loader/src
loader
platform/windows

View file

@ -127,19 +127,19 @@ std::string Log::toString(bool logTime, uint32_t nestLevel) const {
switch (m_severity.m_value) {
case Severity::Debug:
res += " DBG";
res += " DEBUG";
break;
case Severity::Info:
res += " INF";
res += " INFO ";
break;
case Severity::Warning:
res += " WRN";
res += " WARN ";
break;
case Severity::Error:
res += " ERR";
res += " ERROR";
break;
default:
res += " UNK";
res += " ?????";
break;
}

View file

@ -53,26 +53,34 @@ void console::log(std::string const& msg, Severity severity) {
}
int color = 0;
int color2 = -1;
switch (severity) {
case Severity::Debug:
color = 243;
color2 = 250;
break;
case Severity::Info:
color = 33;
color2 = 254;
break;
case Severity::Warning:
color = 229;
color2 = 230;
break;
case Severity::Error:
color = 9;
color2 = 224;
break;
default:
color = 7;
break;
}
auto const colorStr = fmt::format("\x1b[38;5;{}m", color);
auto const newMsg = fmt::format("{}{}\x1b[0m{}", colorStr, msg.substr(0, 12),
msg.substr(12));
auto const color2Str = color2 == -1 ? "\x1b[0m" : fmt::format("\x1b[38;5;{}m", color2);
auto const newMsg = fmt::format(
"{}{}{}{}\x1b[0m",
colorStr, msg.substr(0, 14), color2Str, msg.substr(14)
);
std::cout << newMsg << "\n" << std::flush;
}