mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2024-12-22 20:17:24 +08:00
fix(Logger): not logging anymore after setup is done (#2858)
Regression introduced in #2492 Closes #2773
This commit is contained in:
parent
540ff21b05
commit
e46bb8884b
@ -22,7 +22,6 @@ namespace big
|
||||
m_console_logger = &logger::format_console_simple;
|
||||
}
|
||||
|
||||
toggle_external_console(attach_console);
|
||||
create_backup();
|
||||
m_file_out.open(m_file.get_path(), std::ios_base::out | std::ios_base::trunc);
|
||||
|
||||
@ -33,6 +32,8 @@ namespace big
|
||||
Logger::AddSink([this](LogMessagePtr msg) {
|
||||
format_file(std::move(msg));
|
||||
});
|
||||
|
||||
toggle_external_console(attach_console);
|
||||
}
|
||||
|
||||
void logger::destroy()
|
||||
@ -44,6 +45,19 @@ namespace big
|
||||
|
||||
void logger::toggle_external_console(bool toggle)
|
||||
{
|
||||
if (m_is_console_open == toggle)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_is_console_open = toggle;
|
||||
|
||||
m_console_out.close();
|
||||
if (m_did_console_exist)
|
||||
SetConsoleMode(m_console_handle, m_original_console_mode);
|
||||
|
||||
if (!m_did_console_exist)
|
||||
FreeConsole();
|
||||
|
||||
if (toggle)
|
||||
{
|
||||
if (m_did_console_exist = ::AttachConsole(GetCurrentProcessId()); !m_did_console_exist)
|
||||
@ -60,23 +74,12 @@ namespace big
|
||||
|
||||
// terminal like behaviour enable full color support
|
||||
console_mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
|
||||
// prevent clicking in terminal from suspending our main thread
|
||||
console_mode &= ~(ENABLE_QUICK_EDIT_MODE);
|
||||
|
||||
SetConsoleMode(m_console_handle, console_mode);
|
||||
}
|
||||
|
||||
m_console_out.open("CONOUT$", std::ios_base::out | std::ios_base::app);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_console_out.close();
|
||||
if (m_did_console_exist)
|
||||
SetConsoleMode(m_console_handle, m_original_console_mode);
|
||||
|
||||
if (!m_did_console_exist)
|
||||
FreeConsole();
|
||||
}
|
||||
|
||||
void logger::create_backup()
|
||||
@ -119,6 +122,11 @@ namespace big
|
||||
|
||||
void logger::format_console(const LogMessagePtr msg)
|
||||
{
|
||||
if (!m_is_console_open)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto color = get_color(msg->Level());
|
||||
|
||||
const auto timestamp = std::format("{0:%H:%M:%S}", msg->Timestamp());
|
||||
@ -133,6 +141,11 @@ namespace big
|
||||
|
||||
void logger::format_console_simple(const LogMessagePtr msg)
|
||||
{
|
||||
if (!m_is_console_open)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto color = get_color(msg->Level());
|
||||
|
||||
const auto timestamp = std::format("{0:%H:%M:%S}", msg->Timestamp());
|
||||
|
@ -28,6 +28,7 @@ namespace big
|
||||
private:
|
||||
bool m_attach_console = true;
|
||||
bool m_did_console_exist = false;
|
||||
bool m_is_console_open = false;
|
||||
|
||||
void (logger::*m_console_logger)(const LogMessagePtr msg) = &logger::format_console;
|
||||
|
||||
@ -59,4 +60,4 @@ namespace big
|
||||
};
|
||||
|
||||
inline logger g_log{};
|
||||
}
|
||||
}
|
||||
|
@ -152,9 +152,8 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
||||
g_file_manager.init(base_dir);
|
||||
|
||||
g.init(g_file_manager.get_project_file("./settings.json"));
|
||||
LOG(INFO) << "Settings Loaded.";
|
||||
|
||||
g_log.initialize("YimMenu", g_file_manager.get_project_file("./cout.log"), g.debug.external_console);
|
||||
LOG(INFO) << "Settings Loaded and logger initialized.";
|
||||
|
||||
LOG(INFO) << "Yim's Menu Initializing";
|
||||
LOGF(INFO, "Git Info\n\tBranch:\t{}\n\tHash:\t{}\n\tDate:\t{}", version::GIT_BRANCH, version::GIT_SHA1, version::GIT_DATE);
|
||||
|
Loading…
Reference in New Issue
Block a user