From 8c4f38664161b0c71e7c22d7b2142b5c70ae9173 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 11 Mar 2024 14:06:39 +0200 Subject: [PATCH] made an option for logging to be synced by default instead of async --- src/common/config.cpp | 7 +++++++ src/common/config.h | 1 + src/common/logging/backend.cpp | 33 ++++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 89007ab0..96c71c4f 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -13,6 +13,7 @@ bool isNeo = false; u32 screenWidth = 1280; u32 screenHeight = 720; std::string logFilter; +std::string logType = "sync"; bool isDebugDump = false; bool isNeoMode() { @@ -31,6 +32,10 @@ std::string getLogFilter() { return logFilter; } +std::string getLogType() { + return logType; +} + bool debugDump() { return isDebugDump; } @@ -59,6 +64,7 @@ void load(const std::filesystem::path& path) { isNeo = toml::find_or(general, "isPS4Pro", false); logFilter = toml::find_or(general, "logFilter", ""); + logType = toml::find_or(general, "logType", "sync"); } } if (data.contains("GPU")) { @@ -100,6 +106,7 @@ void save(const std::filesystem::path& path) { data["General"]["isPS4Pro"] = isNeo; data["General"]["logFilter"] = logFilter; + data["General"]["logType"] = logType; data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenHeight"] = screenHeight; data["Debug"]["DebugDump"] = isDebugDump; diff --git a/src/common/config.h b/src/common/config.h index 4dcb1264..114ef55f 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -12,6 +12,7 @@ void save(const std::filesystem::path& path); bool isNeoMode(); std::string getLogFilter(); +std::string getLogType(); u32 getScreenWidth(); u32 getScreenHeight(); diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 9c82d65a..68bbcdb8 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -175,15 +175,30 @@ public: using std::chrono::microseconds; using std::chrono::steady_clock; - message_queue.EmplaceWait(Entry{ - .timestamp = duration_cast(steady_clock::now() - time_origin), - .log_class = log_class, - .log_level = log_level, - .filename = filename, - .line_num = line_num, - .function = function, - .message = std::move(message), - }); + if (Config::getLogType() == "async") { + + message_queue.EmplaceWait(Entry{ + .timestamp = duration_cast(steady_clock::now() - time_origin), + .log_class = log_class, + .log_level = log_level, + .filename = filename, + .line_num = line_num, + .function = function, + .message = std::move(message), + }); + } else { + + const Entry entry = { + .timestamp = duration_cast(steady_clock::now() - time_origin), + .log_class = log_class, + .log_level = log_level, + .filename = filename, + .line_num = line_num, + .function = function, + .message = std::move(message), + }; + ForEachBackend([&entry](auto& backend) { backend.Write(entry); }); + } } private: