fix(logging): all messages would be printed as fatal error

This commit is contained in:
maelstrom 2025-03-20 22:38:00 +01:00
parent 5d97ef58f5
commit b9e35520ad
2 changed files with 6 additions and 4 deletions

View file

@ -36,7 +36,7 @@ void Logger::log(std::string message, Logger::LogLevel logLevel) {
std::string formattedLogLine = std::format("[{:%Y-%m-%d %X}] [{}] {}", now, logLevelStr, message);
logStream << formattedLogLine << std::endl;
printf("FATAL ERROR: %s\n", message.c_str());
printf("%s\n", formattedLogLine.c_str());
if (logLevel == Logger::LogLevel::FATAL_ERROR) {
displayErrorMessage(message);

View file

@ -25,7 +25,7 @@ std::string getProgramDataDir() {
}
void displayErrorMessage(std::string message) {
fprintf(stderr, "%s\n", message.c_str());
fprintf(stderr, "FATAL ERROR: %s\n", message.c_str());
}
#endif // GNU/Linux
@ -37,6 +37,7 @@ void displayErrorMessage(std::string message) {
#include <cstdlib>
#include <shlobj.h>
#include <winuser.h>
#include <wincon.h>
std::string getProgramDataDir() {
CHAR localAppData[MAX_PATH];
@ -49,8 +50,9 @@ std::string getProgramDataDir() {
}
void displayErrorMessage(std::string message) {
fprintf(stderr, "%s\n", message.c_str());
MessageBoxA(NULL, message.c_str(), "Fatal Error", MB_OK | MB_ICONERROR);
fprintf(stderr, "FATAL ERROR: %s\n", message.c_str());
if (!GetConsoleWindow())
MessageBoxA(NULL, message.c_str(), "Fatal Error", MB_OK | MB_ICONERROR);
}
#endif // WIN32