mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
Merge pull request #5770 from ligfx/lognewconfig
LogManager: use layered config
This commit is contained in:
commit
6fe33f844f
@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
#include "Common/Assert.h"
|
||||
#include "Common/Config/Config.h"
|
||||
@ -144,4 +145,34 @@ const std::string& GetLayerName(LayerType layer)
|
||||
};
|
||||
return layer_to_name.at(layer);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator==(const ConfigLocation& other) const
|
||||
{
|
||||
return std::tie(system, section, key) == std::tie(other.system, other.section, other.key);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator!=(const ConfigLocation& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator<(const ConfigLocation& other) const
|
||||
{
|
||||
return std::tie(system, section, key) < std::tie(other.system, other.section, other.key);
|
||||
}
|
||||
|
||||
LayerType GetActiveLayerForConfig(const ConfigLocation& config)
|
||||
{
|
||||
for (auto layer : SEARCH_ORDER)
|
||||
{
|
||||
if (!LayerExists(layer))
|
||||
continue;
|
||||
|
||||
if (GetLayer(layer)->Exists(config.system, config.section, config.key))
|
||||
return layer;
|
||||
}
|
||||
|
||||
// If config is not present in any layer, base layer is considered active.
|
||||
return LayerType::Base;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,24 @@
|
||||
|
||||
namespace Config
|
||||
{
|
||||
struct ConfigLocation
|
||||
{
|
||||
System system;
|
||||
std::string section;
|
||||
std::string key;
|
||||
|
||||
bool operator==(const ConfigLocation& other) const;
|
||||
bool operator!=(const ConfigLocation& other) const;
|
||||
bool operator<(const ConfigLocation& other) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ConfigInfo
|
||||
{
|
||||
ConfigLocation location;
|
||||
T default_value;
|
||||
};
|
||||
|
||||
using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
|
||||
using ConfigChangedCallback = std::function<void()>;
|
||||
|
||||
@ -45,4 +63,60 @@ void ClearCurrentRunLayer();
|
||||
const std::string& GetSystemName(System system);
|
||||
System GetSystemFromName(const std::string& system);
|
||||
const std::string& GetLayerName(LayerType layer);
|
||||
LayerType GetActiveLayerForConfig(const ConfigLocation&);
|
||||
|
||||
template <typename T>
|
||||
T Get(LayerType layer, const ConfigInfo<T>& info)
|
||||
{
|
||||
return GetLayer(layer)
|
||||
->GetOrCreateSection(info.location.system, info.location.section)
|
||||
->template Get<T>(info.location.key, info.default_value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Get(const ConfigInfo<T>& info)
|
||||
{
|
||||
return Get(LayerType::Meta, info);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T GetBase(const ConfigInfo<T>& info)
|
||||
{
|
||||
return Get(LayerType::Base, info);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
|
||||
{
|
||||
return GetActiveLayerForConfig(info.location);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
GetLayer(layer)
|
||||
->GetOrCreateSection(info.location.system, info.location.section)
|
||||
->Set(info.location.key, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetBase(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
Set<T>(LayerType::Base, info, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetCurrent(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
Set<T>(LayerType::CurrentRun, info, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetBaseOrCurrent(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
if (GetActiveLayerForConfig(info) == LayerType::Base)
|
||||
Set<T>(LayerType::Base, info, value);
|
||||
else
|
||||
Set<T>(LayerType::CurrentRun, info, value);
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
#include <string>
|
||||
|
||||
#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<bool> LOGGER_WRITE_TO_FILE{
|
||||
{Config::System::Logger, "Options", "WriteToFile"}, false};
|
||||
const Config::ConfigInfo<bool> LOGGER_WRITE_TO_CONSOLE{
|
||||
{Config::System::Logger, "Options", "WriteToConsole"}, true};
|
||||
const Config::ConfigInfo<bool> LOGGER_WRITE_TO_WINDOW{
|
||||
{Config::System::Logger, "Options", "WriteToWindow"}, true};
|
||||
const Config::ConfigInfo<int> LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, 0};
|
||||
|
||||
class FileLogListener : public LogListener
|
||||
{
|
||||
public:
|
||||
@ -40,7 +48,6 @@ public:
|
||||
bool IsValid() const { return m_logfile.good(); }
|
||||
bool IsEnabled() const { return m_enable; }
|
||||
void SetEnable(bool enable) { m_enable = enable; }
|
||||
// const char* GetName() const { return "file"; }
|
||||
private:
|
||||
std::mutex m_log_lock;
|
||||
std::ofstream m_logfile;
|
||||
@ -121,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)
|
||||
@ -143,12 +139,13 @@ LogManager::LogManager()
|
||||
verbosity = MAX_LOGLEVEL;
|
||||
|
||||
SetLogLevel(static_cast<LogTypes::LOG_LEVELS>(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<bool>{{Config::System::Logger, "Logs", container.m_short_name}, false});
|
||||
|
||||
m_path_cutoff_point = DeterminePathCutOffPoint();
|
||||
}
|
||||
@ -162,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<int>(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,
|
||||
|
@ -31,8 +31,8 @@
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Core/Boot/Boot.h"
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
||||
#include "Core/ConfigLoaders/NetPlayConfigLoader.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
|
@ -25,7 +25,6 @@ set(SRCS
|
||||
Boot/Boot_WiiWAD.cpp
|
||||
Boot/DolReader.cpp
|
||||
Boot/ElfReader.cpp
|
||||
Config/Config.cpp
|
||||
Config/GraphicsSettings.cpp
|
||||
ConfigLoaders/BaseConfigLoader.cpp
|
||||
ConfigLoaders/GameConfigLoader.cpp
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
bool ConfigLocation::operator==(const ConfigLocation& other) const
|
||||
{
|
||||
return std::tie(system, section, key) == std::tie(other.system, other.section, other.key);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator!=(const ConfigLocation& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
bool ConfigLocation::operator<(const ConfigLocation& other) const
|
||||
{
|
||||
return std::tie(system, section, key) < std::tie(other.system, other.section, other.key);
|
||||
}
|
||||
|
||||
LayerType GetActiveLayerForConfig(const ConfigLocation& config)
|
||||
{
|
||||
for (auto layer : SEARCH_ORDER)
|
||||
{
|
||||
if (!LayerExists(layer))
|
||||
continue;
|
||||
|
||||
if (GetLayer(layer)->Exists(config.system, config.section, config.key))
|
||||
return layer;
|
||||
}
|
||||
|
||||
// If config is not present in any layer, base layer is considered active.
|
||||
return LayerType::Base;
|
||||
}
|
||||
|
||||
} // namespace Config
|
@ -1,90 +0,0 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/Config/Enums.h"
|
||||
|
||||
namespace Config
|
||||
{
|
||||
struct ConfigLocation
|
||||
{
|
||||
System system;
|
||||
std::string section;
|
||||
std::string key;
|
||||
|
||||
bool operator==(const ConfigLocation& other) const;
|
||||
bool operator!=(const ConfigLocation& other) const;
|
||||
bool operator<(const ConfigLocation& other) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ConfigInfo
|
||||
{
|
||||
ConfigLocation location;
|
||||
T default_value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T Get(LayerType layer, const ConfigInfo<T>& info)
|
||||
{
|
||||
return GetLayer(layer)
|
||||
->GetOrCreateSection(info.location.system, info.location.section)
|
||||
->template Get<T>(info.location.key, info.default_value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Get(const ConfigInfo<T>& info)
|
||||
{
|
||||
return Get(LayerType::Meta, info);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T GetBase(const ConfigInfo<T>& info)
|
||||
{
|
||||
return Get(LayerType::Base, info);
|
||||
}
|
||||
|
||||
LayerType GetActiveLayerForConfig(const ConfigLocation&);
|
||||
|
||||
template <typename T>
|
||||
LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
|
||||
{
|
||||
return GetActiveLayerForConfig(info.location);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
GetLayer(layer)
|
||||
->GetOrCreateSection(info.location.system, info.location.section)
|
||||
->Set(info.location.key, value);
|
||||
InvokeConfigChangedCallbacks();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetBase(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
Set<T>(LayerType::Base, info, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetCurrent(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
Set<T>(LayerType::CurrentRun, info, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetBaseOrCurrent(const ConfigInfo<T>& info, const T& value)
|
||||
{
|
||||
if (GetActiveLayerForConfig(info) == LayerType::Base)
|
||||
Set<T>(LayerType::Base, info, value);
|
||||
else
|
||||
Set<T>(LayerType::CurrentRun, info, value);
|
||||
}
|
||||
|
||||
} // namespace Config
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
||||
namespace Config
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
|
||||
namespace Config
|
||||
{
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "Common/IniFile.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Core/ConfigLoaders/IsSettingSaveable.h"
|
||||
|
||||
namespace ConfigLoaders
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Core/Config/GraphicsSettings.h"
|
||||
#include "Core/ConfigLoaders/IsSettingSaveable.h"
|
||||
|
||||
|
@ -7,13 +7,16 @@
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Core/Config/GraphicsSettings.h"
|
||||
|
||||
namespace ConfigLoaders
|
||||
{
|
||||
bool IsSettingSaveable(const Config::ConfigLocation& config_location)
|
||||
{
|
||||
if (config_location.system == Config::System::Logger)
|
||||
return true;
|
||||
|
||||
const static std::vector<Config::ConfigLocation> s_setting_saveable{
|
||||
// Graphics.Hardware
|
||||
|
||||
|
@ -45,7 +45,6 @@
|
||||
<ClCompile Include="Boot\Boot_WiiWAD.cpp" />
|
||||
<ClCompile Include="Boot\DolReader.cpp" />
|
||||
<ClCompile Include="Boot\ElfReader.cpp" />
|
||||
<ClCompile Include="Config\Config.cpp" />
|
||||
<ClCompile Include="Config\GraphicsSettings.cpp" />
|
||||
<ClCompile Include="ConfigLoaders\BaseConfigLoader.cpp" />
|
||||
<ClCompile Include="ConfigLoaders\GameConfigLoader.cpp" />
|
||||
@ -301,7 +300,6 @@
|
||||
<ClInclude Include="Boot\DolReader.h" />
|
||||
<ClInclude Include="Boot\ElfReader.h" />
|
||||
<ClInclude Include="Boot\ElfTypes.h" />
|
||||
<ClInclude Include="Config\Config.h" />
|
||||
<ClInclude Include="Config\GraphicsSettings.h" />
|
||||
<ClInclude Include="ConfigLoaders\BaseConfigLoader.h" />
|
||||
<ClInclude Include="ConfigLoaders\GameConfigLoader.h" />
|
||||
|
@ -871,9 +871,6 @@
|
||||
<ClCompile Include="ConfigLoaders\IsSettingSaveable.cpp">
|
||||
<Filter>ConfigLoader</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Config\Config.cpp">
|
||||
<Filter>Config</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Config\GraphicsSettings.cpp">
|
||||
<Filter>Config</Filter>
|
||||
</ClCompile>
|
||||
@ -1523,9 +1520,6 @@
|
||||
<ClInclude Include="ConfigLoaders\IsSettingSaveable.h">
|
||||
<Filter>ConfigLoader</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\Config.h">
|
||||
<Filter>Config</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\GraphicsSettings.h">
|
||||
<Filter>Config</Filter>
|
||||
</ClInclude>
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsBool.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
|
||||
#include <QFont>
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsChoice.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
|
||||
GraphicsChoice::GraphicsChoice(const QStringList& options, const Config::ConfigInfo<int>& setting)
|
||||
: m_setting(setting)
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "DolphinQt2/Config/Graphics/GraphicsSlider.h"
|
||||
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Common/Config/Config.h"
|
||||
|
||||
GraphicsSlider::GraphicsSlider(int minimum, int maximum, const Config::ConfigInfo<int>& setting,
|
||||
int tick)
|
||||
|
@ -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()
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
@ -55,6 +55,7 @@ public:
|
||||
Core::UndeclareAsCPUThread();
|
||||
File::DeleteDirRecursively(m_profile_path);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_profile_path;
|
||||
};
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <unordered_set>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Core/Config/Config.h"
|
||||
#include "Core/HW/MMIO.h"
|
||||
#include "UICommon/UICommon.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user