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.
This commit is contained in:
ameerj 2023-06-24 03:05:04 +03:00 committed by GPUCode
parent a8340395a3
commit 98e9f4c32e
4 changed files with 16 additions and 11 deletions

View file

@ -171,6 +171,7 @@ static QString PrettyProductName() {
GMainWindow::GMainWindow(Core::System& system_)
: ui{std::make_unique<Ui::MainWindow>()}, system{system_}, movie{Core::Movie::GetInstance()},
config{std::make_unique<Config>()}, 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(); });

View file

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <chrono>
#include <exception>
#include <thread>
#include <vector>
#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);

View file

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <exception>
#include <memory>
#include <stdexcept>
#include <utility>
@ -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<System>(new System);
}

View file

@ -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();