From 4632ab2912455825b3cc9abb4e99237aa5a9e05a Mon Sep 17 00:00:00 2001
From: swurl <swurl@swurl.xyz>
Date: Thu, 8 May 2025 06:20:20 +0000
Subject: [PATCH] Runtime option for flushing logs by line (#90)

Signed-off-by: swurl <swurl@swurl.xyz>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/90
Co-authored-by: swurl <swurl@swurl.xyz>
Co-committed-by: swurl <swurl@swurl.xyz>
---
 CMakeLists.txt                             |  6 --
 src/common/logging/backend.cpp             | 12 ++--
 src/common/settings.h                      |  1 +
 src/yuzu/configuration/configure_debug.cpp |  2 +
 src/yuzu/configuration/configure_debug.ui  | 65 ++++++++++++----------
 5 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 41ad4fc07c..b88ab64e53 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -73,8 +73,6 @@ option(YUZU_ENABLE_LTO "Enable link-time optimization" OFF)
 
 option(YUZU_DOWNLOAD_TIME_ZONE_DATA "Always download time zone binaries" OFF)
 
-option(YUZU_LOG_BY_LINE "Flush log data by the line rather than 4KB buffers" OFF)
-
 option(YUZU_ENABLE_PORTABLE "Allow yuzu to enable portable mode if a user folder is found in the CWD" ON)
 
 CMAKE_DEPENDENT_OPTION(YUZU_USE_FASTER_LD "Check if a faster linker is available" ON "NOT WIN32" OFF)
@@ -287,10 +285,6 @@ if (ARCHITECTURE_arm64 AND (ANDROID OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux"))
     add_definitions(-DHAS_NCE=1)
 endif()
 
-if (YUZU_LOG_BY_LINE)
-    add_definitions(-DYUZU_LOG_BY_LINE=1)
-endif()
-
 # Configure C++ standard
 # ===========================
 
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 5ce1c2582e..3b400c6566 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -88,8 +88,8 @@ public:
         auto old_filename = filename;
         old_filename += ".old.txt";
 
-        // Existence checks are done within the functions themselves.
-        // We don't particularly care if these succeed or not.
+               // Existence checks are done within the functions themselves.
+               // We don't particularly care if these succeed or not.
         static_cast<void>(FS::RemoveFile(old_filename));
         static_cast<void>(FS::RenameFile(filename, old_filename));
 
@@ -106,10 +106,10 @@ public:
 
         bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n'));
 
-        // Option to log each line rather than 4k buffers
-#ifdef YUZU_LOG_BY_LINE
-        file->Flush();
-#endif
+               // Option to log each line rather than 4k buffers
+        if (Settings::values.log_flush_lines.GetValue()) {
+            file->Flush();
+        }
 
         using namespace Common::Literals;
         // Prevent logs from exceeding a set maximum size in the event that log entries are spammed.
diff --git a/src/common/settings.h b/src/common/settings.h
index 646051f24c..709ca03e7c 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -627,6 +627,7 @@ struct Values {
 
     // Miscellaneous
     Setting<std::string> log_filter{linkage, "*:Info", "log_filter", Category::Miscellaneous};
+    Setting<bool> log_flush_lines{linkage, false, "flush_lines", Category::Miscellaneous};
     Setting<bool> use_dev_keys{linkage, false, "use_dev_keys", Category::Miscellaneous};
 
     // Network
diff --git a/src/yuzu/configuration/configure_debug.cpp b/src/yuzu/configuration/configure_debug.cpp
index 1010038b76..5f23eea3d3 100644
--- a/src/yuzu/configuration/configure_debug.cpp
+++ b/src/yuzu/configuration/configure_debug.cpp
@@ -39,6 +39,7 @@ void ConfigureDebug::SetConfiguration() {
     ui->toggle_console->setEnabled(runtime_lock);
     ui->toggle_console->setChecked(UISettings::values.show_console.GetValue());
     ui->log_filter_edit->setText(QString::fromStdString(Settings::values.log_filter.GetValue()));
+    ui->flush_line->setChecked(Settings::values.log_flush_lines.GetValue());
     ui->homebrew_args_edit->setText(
         QString::fromStdString(Settings::values.program_args.GetValue()));
     ui->fs_access_log->setEnabled(runtime_lock);
@@ -88,6 +89,7 @@ void ConfigureDebug::ApplyConfiguration() {
     Settings::values.gdbstub_port = ui->gdbport_spinbox->value();
     UISettings::values.show_console = ui->toggle_console->isChecked();
     Settings::values.log_filter = ui->log_filter_edit->text().toStdString();
+    Settings::values.log_flush_lines = ui->flush_line->isChecked();
     Settings::values.program_args = ui->homebrew_args_edit->text().toStdString();
     Settings::values.enable_fs_access_log = ui->fs_access_log->isChecked();
     Settings::values.reporting_services = ui->reporting_services->isChecked();
diff --git a/src/yuzu/configuration/configure_debug.ui b/src/yuzu/configuration/configure_debug.ui
index d842b01352..68c5a67b24 100644
--- a/src/yuzu/configuration/configure_debug.ui
+++ b/src/yuzu/configuration/configure_debug.ui
@@ -18,8 +18,8 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>842</width>
-     <height>741</height>
+     <width>829</width>
+     <height>758</height>
     </rect>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout_1">
@@ -40,7 +40,7 @@
          <string>Debugger</string>
         </property>
         <property name="alignment">
-         <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+         <set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
         </property>
         <property name="flat">
          <bool>false</bool>
@@ -59,7 +59,7 @@
            </property>
            <layout class="QVBoxLayout" name="verticalLayout">
             <property name="sizeConstraint">
-             <enum>QLayout::SetDefaultConstraint</enum>
+             <enum>QLayout::SizeConstraint::SetDefaultConstraint</enum>
             </property>
             <property name="leftMargin">
              <number>0</number>
@@ -355,10 +355,10 @@
          <item row="10" column="0">
           <spacer name="verticalSpacer_5">
            <property name="orientation">
-            <enum>Qt::Vertical</enum>
+            <enum>Qt::Orientation::Vertical</enum>
            </property>
            <property name="sizeType">
-            <enum>QSizePolicy::Preferred</enum>
+            <enum>QSizePolicy::Policy::Preferred</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
@@ -452,10 +452,10 @@
          <item row="7" column="0">
           <spacer name="verticalSpacer_4">
            <property name="orientation">
-            <enum>Qt::Vertical</enum>
+            <enum>Qt::Orientation::Vertical</enum>
            </property>
            <property name="sizeType">
-            <enum>QSizePolicy::Expanding</enum>
+            <enum>QSizePolicy::Policy::Expanding</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
@@ -474,37 +474,27 @@
          <string>Debugging</string>
         </property>
         <layout class="QGridLayout" name="gridLayout_3">
-         <item row="0" column="0">
-          <widget class="QCheckBox" name="fs_access_log">
-           <property name="text">
-            <string>Enable FS Access Log</string>
-           </property>
-          </widget>
-         </item>
          <item row="3" column="0">
-          <widget class="QCheckBox" name="dump_audio_commands">
-           <property name="toolTip">
-            <string>Enable this to output the latest generated audio command list to the console. Only affects games using the audio renderer.</string>
-           </property>
-           <property name="text">
-            <string>Dump Audio Commands To Console**</string>
-           </property>
-          </widget>
-         </item>
-         <item row="2" column="0">
           <widget class="QCheckBox" name="reporting_services">
            <property name="text">
             <string>Enable Verbose Reporting Services**</string>
            </property>
           </widget>
          </item>
-         <item row="5" column="0">
+         <item row="1" column="0">
+          <widget class="QCheckBox" name="fs_access_log">
+           <property name="text">
+            <string>Enable FS Access Log</string>
+           </property>
+          </widget>
+         </item>
+         <item row="6" column="0">
           <spacer name="verticalSpacer_3">
            <property name="orientation">
-            <enum>Qt::Vertical</enum>
+            <enum>Qt::Orientation::Vertical</enum>
            </property>
            <property name="sizeType">
-            <enum>QSizePolicy::Expanding</enum>
+            <enum>QSizePolicy::Policy::Expanding</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
@@ -514,6 +504,23 @@
            </property>
           </spacer>
          </item>
+         <item row="4" column="0">
+          <widget class="QCheckBox" name="dump_audio_commands">
+           <property name="toolTip">
+            <string>Enable this to output the latest generated audio command list to the console. Only affects games using the audio renderer.</string>
+           </property>
+           <property name="text">
+            <string>Dump Audio Commands To Console**</string>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="0">
+          <widget class="QCheckBox" name="flush_line">
+           <property name="text">
+            <string>Flush log output on each line</string>
+           </property>
+          </widget>
+         </item>
         </layout>
        </widget>
       </item>
@@ -522,7 +529,7 @@
     <item>
      <spacer name="verticalSpacer">
       <property name="orientation">
-       <enum>Qt::Vertical</enum>
+       <enum>Qt::Orientation::Vertical</enum>
       </property>
       <property name="sizeHint" stdset="0">
        <size>