mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-01-09 00:12:27 +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 <user/paths.h>
|
||||||
#include <kernel/xdbf.h>
|
#include <kernel/xdbf.h>
|
||||||
#include <install/installer.h>
|
#include <install/installer.h>
|
||||||
|
#include <os/logger.h>
|
||||||
#include <ui/installer_wizard.h>
|
#include <ui/installer_wizard.h>
|
||||||
|
|
||||||
#define GAME_XEX_PATH "game:\\default.xex"
|
#define GAME_XEX_PATH "game:\\default.xex"
|
||||||
|
|
@ -144,6 +145,8 @@ uint32_t LdrLoadModule(const char* path)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
os::logger::Init();
|
||||||
|
|
||||||
bool forceInstaller = false;
|
bool forceInstaller = false;
|
||||||
bool forceDLCInstaller = false;
|
bool forceDLCInstaller = false;
|
||||||
for (uint32_t i = 1; i < argc; i++)
|
for (uint32_t i = 1; i < argc; i++)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
#include <os/logger.h>
|
#include <os/logger.h>
|
||||||
#include <os/logger_detail.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);
|
detail::Log(str, type, func);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,5 +51,6 @@
|
||||||
|
|
||||||
namespace os::logger
|
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
|
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 <os/logger_detail.h>
|
||||||
|
#include <print>
|
||||||
|
|
||||||
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
|
||||||
#define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
|
#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)
|
switch (type)
|
||||||
{
|
{
|
||||||
case ELogType::Utility:
|
case ELogType::Utility:
|
||||||
|
|
@ -31,11 +34,11 @@ void os::logger::detail::Log(const std::string& str, detail::ELogType type, cons
|
||||||
|
|
||||||
if (func)
|
if (func)
|
||||||
{
|
{
|
||||||
printf("[%s] %s\n", func, str.c_str());
|
std::println("[{}] {}", func, str);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("%s\n", str.c_str());
|
std::println("{}", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);
|
SetConsoleTextAttribute(g_hStandardOutput, FOREGROUND_WHITE);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue