Implemented cross-platform logger framework (and clean-up)

This commit is contained in:
Hyper
2024-12-12 22:12:29 +00:00
parent b9bd137659
commit 0813be2acf
17 changed files with 453 additions and 416 deletions
+47
View File
@@ -0,0 +1,47 @@
#include <os/logger_detail.h>
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
#define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
HANDLE g_hStandardOutput = nullptr;
void os::logger::detail::Log(const std::string& str, detail::ELogType type, const char* func)
{
#if !_DEBUG
if (type == ELogType::Utility)
return;
#endif
if (!g_hStandardOutput)
g_hStandardOutput = GetStdHandle(STD_OUTPUT_HANDLE);
switch (type)
{
case ELogType::Utility:
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
break;
case ELogType::Warning:
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_YELLOW | FOREGROUND_INTENSITY);
break;
case ELogType::Error:
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_RED | FOREGROUND_INTENSITY);
break;
default:
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);
break;
}
if (func)
{
printf("[%s] %s\n", func, str.c_str());
}
else
{
printf("%s\n", str.c_str());
}
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);
}