diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 8288e1d796..45d10de6a2 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -9,8 +9,8 @@ #include #include "Common/CommonPaths.h" +#include "Common/Config/Config.h" #include "Common/FileUtil.h" -#include "Common/IniFile.h" #include "Common/Logging/ConsoleListener.h" #include "Common/Logging/Log.h" #include "Common/Logging/LogManager.h" @@ -19,6 +19,14 @@ constexpr size_t MAX_MSGLEN = 1024; +const Config::ConfigInfo LOGGER_WRITE_TO_FILE{ + {Config::System::Logger, "Options", "WriteToFile"}, false}; +const Config::ConfigInfo LOGGER_WRITE_TO_CONSOLE{ + {Config::System::Logger, "Options", "WriteToConsole"}, true}; +const Config::ConfigInfo LOGGER_WRITE_TO_WINDOW{ + {Config::System::Logger, "Options", "WriteToWindow"}, true}; +const Config::ConfigInfo LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, 0}; + class FileLogListener : public LogListener { public: @@ -120,20 +128,9 @@ LogManager::LogManager() new FileLogListener(File::GetUserPath(F_MAINLOG_IDX))); RegisterListener(LogListener::CONSOLE_LISTENER, new ConsoleListener()); - IniFile ini; - ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX)); - IniFile::Section* logs = ini.GetOrCreateSection("Logs"); - IniFile::Section* options = ini.GetOrCreateSection("Options"); - bool write_file; - bool write_console; - bool write_window; - options->Get("WriteToFile", &write_file, false); - options->Get("WriteToConsole", &write_console, true); - options->Get("WriteToWindow", &write_window, true); - // Set up log listeners - int verbosity; - options->Get("Verbosity", &verbosity, 0); + int verbosity = Config::Get(LOGGER_VERBOSITY); + ; // Ensure the verbosity level is valid if (verbosity < 1) @@ -142,12 +139,13 @@ LogManager::LogManager() verbosity = MAX_LOGLEVEL; SetLogLevel(static_cast(verbosity)); - EnableListener(LogListener::FILE_LISTENER, write_file); - EnableListener(LogListener::CONSOLE_LISTENER, write_console); - EnableListener(LogListener::LOG_WINDOW_LISTENER, write_window); + EnableListener(LogListener::FILE_LISTENER, Config::Get(LOGGER_WRITE_TO_FILE)); + EnableListener(LogListener::CONSOLE_LISTENER, Config::Get(LOGGER_WRITE_TO_CONSOLE)); + EnableListener(LogListener::LOG_WINDOW_LISTENER, Config::Get(LOGGER_WRITE_TO_WINDOW)); for (LogContainer& container : m_log) - logs->Get(container.m_short_name, &container.m_enable, false); + container.m_enable = Config::Get( + Config::ConfigInfo{{Config::System::Logger, "Logs", container.m_short_name}, false}); m_path_cutoff_point = DeterminePathCutOffPoint(); } @@ -161,20 +159,18 @@ LogManager::~LogManager() void LogManager::SaveSettings() { - IniFile ini; - ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX)); + Config::SetBaseOrCurrent(LOGGER_WRITE_TO_FILE, IsListenerEnabled(LogListener::FILE_LISTENER)); + Config::SetBaseOrCurrent(LOGGER_WRITE_TO_CONSOLE, + IsListenerEnabled(LogListener::CONSOLE_LISTENER)); + Config::SetBaseOrCurrent(LOGGER_WRITE_TO_WINDOW, + IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER)); + Config::SetBaseOrCurrent(LOGGER_VERBOSITY, static_cast(GetLogLevel())); - IniFile::Section* options = ini.GetOrCreateSection("Options"); - options->Set("Verbosity", GetLogLevel()); - options->Set("WriteToFile", m_listener_ids[LogListener::FILE_LISTENER]); - options->Set("WriteToConsole", m_listener_ids[LogListener::CONSOLE_LISTENER]); - options->Set("WriteToWindow", m_listener_ids[LogListener::LOG_WINDOW_LISTENER]); - - // Save all enabled/disabled states of the log types to the config ini. for (const auto& container : m_log) - ini.GetOrCreateSection("Logs")->Set(container.m_short_name, container.m_enable); + Config::SetBaseOrCurrent({{Config::System::Logger, "Logs", container.m_short_name}, false}, + container.m_enable); - ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX)); + Config::Save(); } void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 8dc728f91a..38ea90710f 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -14,6 +14,9 @@ namespace ConfigLoaders { bool IsSettingSaveable(const Config::ConfigLocation& config_location) { + if (config_location.system == Config::System::Logger) + return true; + const static std::vector s_setting_saveable{ // Graphics.Hardware diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 9c45a5c0d9..691644edf5 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -32,10 +32,10 @@ namespace UICommon { void Init() { - LogManager::Init(); Config::Init(); Config::AddLoadLayer(ConfigLoaders::GenerateBaseConfigLoader()); SConfig::Init(); + LogManager::Init(); VideoBackendBase::PopulateList(); WiimoteReal::LoadSettings(); GCAdapter::Init(); @@ -49,9 +49,9 @@ void Shutdown() GCAdapter::Shutdown(); WiimoteReal::Shutdown(); VideoBackendBase::ClearList(); + LogManager::Shutdown(); SConfig::Shutdown(); Config::Shutdown(); - LogManager::Shutdown(); } void CreateDirectories()