mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-12-24 08:52:21 +00:00
logger: make thread safe, use std::string_view with std::println
This commit is contained in:
parent
e7d7431b58
commit
3e21a26f6a
5 changed files with 22 additions and 9 deletions
|
|
@ -16,6 +16,7 @@
|
|||
#include <user/paths.h>
|
||||
#include <kernel/xdbf.h>
|
||||
#include <install/installer.h>
|
||||
#include <os/logger.h>
|
||||
#include <ui/installer_wizard.h>
|
||||
|
||||
#define GAME_XEX_PATH "game:\\default.xex"
|
||||
|
|
@ -144,6 +145,8 @@ uint32_t LdrLoadModule(const char* path)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
os::logger::Init();
|
||||
|
||||
bool forceInstaller = false;
|
||||
bool forceDLCInstaller = false;
|
||||
for (uint32_t i = 1; i < argc; i++)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
#include <os/logger.h>
|
||||
#include <os/logger_detail.h>
|
||||
|
||||
void os::logger::Log(const std::string& str, detail::ELogType type, const char* func)
|
||||
void os::logger::Init()
|
||||
{
|
||||
detail::Init();
|
||||
}
|
||||
|
||||
void os::logger::Log(const std::string_view str, detail::ELogType type, const char* func)
|
||||
{
|
||||
detail::Log(str, type, func);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,5 +51,6 @@
|
|||
|
||||
namespace os::logger
|
||||
{
|
||||
void Log(const std::string& str, detail::ELogType type = detail::ELogType::None, const char* func = nullptr);
|
||||
void Init();
|
||||
void Log(const std::string_view str, detail::ELogType type = detail::ELogType::None, const char* func = nullptr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,5 +12,6 @@ namespace os::logger::detail
|
|||
Error
|
||||
};
|
||||
|
||||
void Log(const std::string& str, ELogType type = ELogType::None, const char* func = nullptr);
|
||||
void Init();
|
||||
void Log(const std::string_view str, ELogType type = ELogType::None, const char* func = nullptr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
#include <os/logger_detail.h>
|
||||
#include <print>
|
||||
|
||||
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
||||
#define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
|
||||
|
||||
HANDLE g_hStandardOutput = nullptr;
|
||||
HANDLE g_hStandardOutput;
|
||||
|
||||
void os::logger::detail::Log(const std::string& str, detail::ELogType type, const char* func)
|
||||
void os::logger::detail::Init()
|
||||
{
|
||||
if (!g_hStandardOutput)
|
||||
g_hStandardOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
g_hStandardOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
}
|
||||
|
||||
void os::logger::detail::Log(const std::string_view str, detail::ELogType type, const char* func)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ELogType::Utility:
|
||||
|
|
@ -31,11 +34,11 @@ void os::logger::detail::Log(const std::string& str, detail::ELogType type, cons
|
|||
|
||||
if (func)
|
||||
{
|
||||
printf("[%s] %s\n", func, str.c_str());
|
||||
std::println("[{}] {}", func, str);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s\n", str.c_str());
|
||||
std::println("{}", str);
|
||||
}
|
||||
|
||||
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue