From 98e9f4c32e196a8d431d93a55058a92df7810ad0 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sat, 24 Jun 2023 03:05:04 +0300 Subject: [PATCH] logging: Fix log filter during initialization The log filter was being ignored on initialization due to the logging instance being initialized before the config instance, so the log filter was set to its default value. This fixes that oversight, along with using descriptive exceptions instead of abort() calls. --- src/citra_qt/main.cpp | 2 +- src/common/logging/backend.cpp | 8 +++++--- src/core/core.cpp | 10 +++++++++- src/core/core.h | 7 +------ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 71f293785..ee1102a21 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -171,6 +171,7 @@ static QString PrettyProductName() { GMainWindow::GMainWindow(Core::System& system_) : ui{std::make_unique()}, system{system_}, movie{Core::Movie::GetInstance()}, config{std::make_unique()}, emu_thread{nullptr} { + Common::Log::Initialize(); Debugger::ToggleConsole(); Settings::LogSettings(); @@ -2853,7 +2854,6 @@ static Qt::HighDpiScaleFactorRoundingPolicy GetHighDpiRoundingPolicy() { } int main(int argc, char* argv[]) { - Common::Log::Initialize(); Common::DetachedTasks detached_tasks; MicroProfileOnThreadCreate("Frontend"); SCOPE_EXIT({ MicroProfileShutdown(); }); diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 58cffa33b..c835a0d85 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include "common/common_paths.h" @@ -177,7 +178,7 @@ public: }; #endif -bool initialization_in_progress_suppress_logging = false; +bool initialization_in_progress_suppress_logging = true; #ifdef CITRA_LINUX_GCC_BACKTRACE [[noreturn]] void SleepForever() { @@ -194,14 +195,15 @@ class Impl { public: static Impl& Instance() { if (!instance) { - abort(); + throw std::runtime_error("Using Logging instance before its initialization"); } return *instance; } static void Initialize() { if (instance) { - abort(); + LOG_WARNING(Log, "Reinitializing logging backend"); + return; } initialization_in_progress_suppress_logging = true; const auto& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); diff --git a/src/core/core.cpp b/src/core/core.cpp index e9aff1a12..4d4d567e9 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include #include @@ -68,9 +69,16 @@ Core::Timing& Global() { System::~System() = default; +System& System::GetInstance() { + if (!s_instance) { + throw std::runtime_error("Using System instance before its initialization"); + } + return *s_instance; +} + void System::InitializeGlobalInstance() { if (s_instance) { - std::abort(); + throw std::runtime_error("Reinitializing Global System instance."); } s_instance = std::unique_ptr(new System); } diff --git a/src/core/core.h b/src/core/core.h index b85febf26..9bc49c9c3 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -73,12 +73,7 @@ public: * Gets the instance of the System singleton class. * @returns Reference to the instance of the System singleton class. */ - [[nodiscard]] static System& GetInstance() { - if (!s_instance) { - std::abort(); - } - return *s_instance; - } + [[nodiscard]] static System& GetInstance(); static void InitializeGlobalInstance();