fix(Logger): not logging anymore after setup is done (#2858)
Regression introduced in #2492 Closes #2773
This commit is contained in:
parent
95259faf59
commit
5f553b3430
@ -22,7 +22,6 @@ namespace big
|
|||||||
m_console_logger = &logger::format_console_simple;
|
m_console_logger = &logger::format_console_simple;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle_external_console(attach_console);
|
|
||||||
create_backup();
|
create_backup();
|
||||||
m_file_out.open(m_file.get_path(), std::ios_base::out | std::ios_base::trunc);
|
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) {
|
Logger::AddSink([this](LogMessagePtr msg) {
|
||||||
format_file(std::move(msg));
|
format_file(std::move(msg));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
toggle_external_console(attach_console);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logger::destroy()
|
void logger::destroy()
|
||||||
@ -44,6 +45,19 @@ namespace big
|
|||||||
|
|
||||||
void logger::toggle_external_console(bool toggle)
|
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 (toggle)
|
||||||
{
|
{
|
||||||
if (m_did_console_exist = ::AttachConsole(GetCurrentProcessId()); !m_did_console_exist)
|
if (m_did_console_exist = ::AttachConsole(GetCurrentProcessId()); !m_did_console_exist)
|
||||||
@ -60,23 +74,12 @@ namespace big
|
|||||||
|
|
||||||
// terminal like behaviour enable full color support
|
// terminal like behaviour enable full color support
|
||||||
console_mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
|
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);
|
SetConsoleMode(m_console_handle, console_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_console_out.open("CONOUT$", std::ios_base::out | std::ios_base::app);
|
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()
|
void logger::create_backup()
|
||||||
@ -119,6 +122,11 @@ namespace big
|
|||||||
|
|
||||||
void logger::format_console(const LogMessagePtr msg)
|
void logger::format_console(const LogMessagePtr msg)
|
||||||
{
|
{
|
||||||
|
if (!m_is_console_open)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto color = get_color(msg->Level());
|
const auto color = get_color(msg->Level());
|
||||||
|
|
||||||
const auto timestamp = std::format("{0:%H:%M:%S}", msg->Timestamp());
|
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)
|
void logger::format_console_simple(const LogMessagePtr msg)
|
||||||
{
|
{
|
||||||
|
if (!m_is_console_open)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto color = get_color(msg->Level());
|
const auto color = get_color(msg->Level());
|
||||||
|
|
||||||
const auto timestamp = std::format("{0:%H:%M:%S}", msg->Timestamp());
|
const auto timestamp = std::format("{0:%H:%M:%S}", msg->Timestamp());
|
||||||
|
@ -28,6 +28,7 @@ namespace big
|
|||||||
private:
|
private:
|
||||||
bool m_attach_console = true;
|
bool m_attach_console = true;
|
||||||
bool m_did_console_exist = false;
|
bool m_did_console_exist = false;
|
||||||
|
bool m_is_console_open = false;
|
||||||
|
|
||||||
void (logger::*m_console_logger)(const LogMessagePtr msg) = &logger::format_console;
|
void (logger::*m_console_logger)(const LogMessagePtr msg) = &logger::format_console;
|
||||||
|
|
||||||
@ -59,4 +60,4 @@ namespace big
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline logger g_log{};
|
inline logger g_log{};
|
||||||
}
|
}
|
||||||
|
@ -152,9 +152,8 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
|||||||
g_file_manager.init(base_dir);
|
g_file_manager.init(base_dir);
|
||||||
|
|
||||||
g.init(g_file_manager.get_project_file("./settings.json"));
|
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);
|
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";
|
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);
|
LOGF(INFO, "Git Info\n\tBranch:\t{}\n\tHash:\t{}\n\tDate:\t{}", version::GIT_BRANCH, version::GIT_SHA1, version::GIT_DATE);
|
||||||
|
Reference in New Issue
Block a user