From c4b072e0e16e5694032349b9d3bb21e587389df9 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 16 Aug 2023 10:34:04 +0300 Subject: [PATCH] configurable loglevel in config file --- src/Util/config.cpp | 21 +++++++++++++++++++++ src/Util/config.h | 6 ++++++ src/Util/log.cpp | 3 +++ 3 files changed, 30 insertions(+) diff --git a/src/Util/config.cpp b/src/Util/config.cpp index e6beab6d..aa5ff8a4 100644 --- a/src/Util/config.cpp +++ b/src/Util/config.cpp @@ -7,8 +7,15 @@ namespace Config { bool isNeo = false; +u32 screenWidth = 1280; +u32 screenHeight = 720; +u32 logLevel = 0; // TRACE = 0 , DEBUG = 1 , INFO = 2 , WARN = 3 , ERROR = 4 , CRITICAL = 5, OFF = 6 bool isNeoMode() { return isNeo; } +u32 getScreenWidth() { return screenWidth; } +u32 getScreenHeight() { return screenHeight; } +u32 getLogLevel() { return logLevel; } + void load(const std::filesystem::path& path) { // If the configuration file does not exist, create it and return std::error_code error; @@ -32,8 +39,19 @@ void load(const std::filesystem::path& path) { auto general = generalResult.unwrap(); isNeo = toml::find_or(general, "isPS4Pro", false); + logLevel = toml::find_or(general, "logLevel", false); } } + if (data.contains("GPU")) { + auto generalResult = toml::expect(data.at("GPU")); + if (generalResult.is_ok()) { + auto general = generalResult.unwrap(); + + screenWidth = toml::find_or(general, "screenWidth", false); + screenHeight = toml::find_or(general, "screenHeight", false); + } + } + int k = 0; } void save(const std::filesystem::path& path) { toml::basic_value data; @@ -54,6 +72,9 @@ void save(const std::filesystem::path& path) { } data["General"]["isPS4Pro"] = isNeo; + data["General"]["logLevel"] = logLevel; + data["GPU"]["screenWidth"] = screenWidth; + data["GPU"]["screenHeight"] = screenHeight; std::ofstream file(path, std::ios::out); file << data; diff --git a/src/Util/config.h b/src/Util/config.h index e243397f..c27cc2df 100644 --- a/src/Util/config.h +++ b/src/Util/config.h @@ -1,9 +1,15 @@ #pragma once #include +#include namespace Config { void load(const std::filesystem::path& path); void save(const std::filesystem::path& path); bool isNeoMode(); +u32 getLogLevel(); + +u32 getScreenWidth(); +u32 getScreenHeight(); + }; // namespace Config \ No newline at end of file diff --git a/src/Util/log.cpp b/src/Util/log.cpp index 935a7d8c..a9c262aa 100644 --- a/src/Util/log.cpp +++ b/src/Util/log.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace logging { std::vector sinks; @@ -17,6 +18,8 @@ int init(bool use_stdout) { spdlog::set_default_logger(std::make_shared("shadps4 logger", begin(sinks), end(sinks))); auto f = std::make_unique("%^|%L|: %v%$", spdlog::pattern_time_type::local, std::string("")); // disable eol spdlog::set_formatter(std::move(f)); + spdlog::set_level(static_cast(Config::getLogLevel())); + spdlog::level::level_enum t = spdlog::get_level(); return 0; // all ok }