From 3dd722ed3f0499788930fc419a980d1891c5b169 Mon Sep 17 00:00:00 2001 From: jcm Date: Sat, 1 Jun 2024 00:31:38 -0500 Subject: [PATCH] Add Settings toggle for log filesize limit --- .../Logging/Targets/FileLogTarget.cs | 8 +++++--- src/Ryujinx.Headless.SDL2/Options.cs | 3 +++ src/Ryujinx.Headless.SDL2/Program.cs | 3 ++- .../Configuration/ConfigurationFileFormat.cs | 7 ++++++- .../Configuration/ConfigurationState.cs | 16 ++++++++++++++++ .../Configuration/LoggerModule.cs | 13 ++++++++++++- src/Ryujinx/Assets/Locales/en_US.json | 2 ++ src/Ryujinx/UI/ViewModels/SettingsViewModel.cs | 3 +++ .../UI/Views/Settings/SettingsLoggingView.axaml | 6 +++++- 9 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs b/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs index 5214812637..0722831733 100644 --- a/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs +++ b/src/Ryujinx.Common/Logging/Targets/FileLogTarget.cs @@ -12,14 +12,16 @@ namespace Ryujinx.Common.Logging.Targets private readonly string _name; private ulong _logLength = 0; private static readonly ulong _maxLogCharacterLength = 500000000; + private static bool _limitsFileSize = true; string ILogTarget.Name { get => _name; } - public FileLogTarget(string name, FileStream fileStream) + public FileLogTarget(string name, FileStream fileStream, bool limitsFileSize) { _name = name; _logWriter = new StreamWriter(fileStream); _formatter = new DefaultLogFormatter(); + _limitsFileSize = limitsFileSize; } public static FileStream PrepareLogFile(string path) @@ -97,12 +99,12 @@ namespace Ryujinx.Common.Logging.Targets { string toWrite = _formatter.Format(args); _logLength += (ulong)toWrite.Length; - if (_logLength <= _maxLogCharacterLength) + + if (_logLength <= _maxLogCharacterLength || !_limitsFileSize) { _logWriter.WriteLine(toWrite); _logWriter.Flush(); } - } public void Dispose() diff --git a/src/Ryujinx.Headless.SDL2/Options.cs b/src/Ryujinx.Headless.SDL2/Options.cs index ea2063758d..4e5731a6df 100644 --- a/src/Ryujinx.Headless.SDL2/Options.cs +++ b/src/Ryujinx.Headless.SDL2/Options.cs @@ -182,6 +182,9 @@ namespace Ryujinx.Headless.SDL2 [Option("graphics-debug-level", Required = false, Default = GraphicsDebugLevel.None, HelpText = "Change Graphics API debug log level.")] public GraphicsDebugLevel LoggingGraphicsDebugLevel { get; set; } + [Option("disable-log-size-limit", Required = false, Default = false, HelpText = "Disable 500MB log file size limit.")] + public bool LoggingDisableLogFileSizeLimit { get; set; } + // Graphics [Option("resolution-scale", Required = false, Default = 1, HelpText = "Resolution Scale. A floating point scale applied to applicable render targets.")] diff --git a/src/Ryujinx.Headless.SDL2/Program.cs b/src/Ryujinx.Headless.SDL2/Program.cs index 85aff67129..eea4f8c8a6 100644 --- a/src/Ryujinx.Headless.SDL2/Program.cs +++ b/src/Ryujinx.Headless.SDL2/Program.cs @@ -437,8 +437,9 @@ namespace Ryujinx.Headless.SDL2 if (logFile != null) { + bool limitsFileSize = !option.LoggingDisableLogFileSizeLimit; Logger.AddTarget(new AsyncLogTargetWrapper( - new FileLogTarget("file", logFile), + new FileLogTarget("file", logFile, limitsFileSize), 1000, AsyncLogTargetOverflowAction.Block )); diff --git a/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs b/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs index af3ad0a1da..fb13befa62 100644 --- a/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs +++ b/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs @@ -15,7 +15,7 @@ namespace Ryujinx.UI.Common.Configuration /// /// The current version of the file format /// - public const int CurrentVersion = 51; + public const int CurrentVersion = 52; /// /// Version of the configuration file format @@ -122,6 +122,11 @@ namespace Ryujinx.UI.Common.Configuration /// public GraphicsDebugLevel LoggingGraphicsDebugLevel { get; set; } + /// + /// Disables the 500MB log file size limit. + /// + public bool LoggingDisableLogFileSizeLimit { get; set; } + /// /// Change System Language /// diff --git a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs index 8420dc5d98..3e71384c76 100644 --- a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs +++ b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs @@ -269,6 +269,11 @@ namespace Ryujinx.UI.Common.Configuration /// public ReactiveObject GraphicsDebugLevel { get; private set; } + /// + /// Disables the 500MB imposed file size limit on logs. + /// + public ReactiveObject DisableLogFileSizeLimit { get; private set; } + public LoggerSection() { EnableDebug = new ReactiveObject(); @@ -283,6 +288,7 @@ namespace Ryujinx.UI.Common.Configuration EnableFileLog = new ReactiveObject(); EnableFileLog.Event += static (sender, e) => LogValueChange(e, nameof(EnableFileLog)); GraphicsDebugLevel = new ReactiveObject(); + DisableLogFileSizeLimit = new ReactiveObject(); } } @@ -683,6 +689,7 @@ namespace Ryujinx.UI.Common.Configuration LoggingEnableFsAccessLog = Logger.EnableFsAccessLog, LoggingFilteredClasses = Logger.FilteredClasses, LoggingGraphicsDebugLevel = Logger.GraphicsDebugLevel, + LoggingDisableLogFileSizeLimit = Logger.DisableLogFileSizeLimit, SystemLanguage = System.Language, SystemRegion = System.Region, SystemTimeZone = System.TimeZone, @@ -790,6 +797,7 @@ namespace Ryujinx.UI.Common.Configuration Logger.EnableTrace.Value = false; Logger.EnableGuest.Value = true; Logger.EnableFsAccessLog.Value = false; + Logger.DisableLogFileSizeLimit.Value = false; Logger.FilteredClasses.Value = Array.Empty(); Logger.GraphicsDebugLevel.Value = GraphicsDebugLevel.None; System.Language.Value = Language.AmericanEnglish; @@ -1477,6 +1485,13 @@ namespace Ryujinx.UI.Common.Configuration configurationFileUpdated = true; } + if (configurationFileFormat.Version < 52) + { + Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 52."); + + configurationFileFormat.LoggingDisableLogFileSizeLimit = false; + } + Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog; Graphics.ResScale.Value = configurationFileFormat.ResScale; Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom; @@ -1497,6 +1512,7 @@ namespace Ryujinx.UI.Common.Configuration Logger.EnableTrace.Value = configurationFileFormat.LoggingEnableTrace; Logger.EnableGuest.Value = configurationFileFormat.LoggingEnableGuest; Logger.EnableFsAccessLog.Value = configurationFileFormat.LoggingEnableFsAccessLog; + Logger.DisableLogFileSizeLimit.Value = configurationFileFormat.LoggingDisableLogFileSizeLimit; Logger.FilteredClasses.Value = configurationFileFormat.LoggingFilteredClasses; Logger.GraphicsDebugLevel.Value = configurationFileFormat.LoggingGraphicsDebugLevel; System.Language.Value = configurationFileFormat.SystemLanguage; diff --git a/src/Ryujinx.UI.Common/Configuration/LoggerModule.cs b/src/Ryujinx.UI.Common/Configuration/LoggerModule.cs index 9cb283593e..091b93da91 100644 --- a/src/Ryujinx.UI.Common/Configuration/LoggerModule.cs +++ b/src/Ryujinx.UI.Common/Configuration/LoggerModule.cs @@ -21,6 +21,7 @@ namespace Ryujinx.UI.Common.Configuration ConfigurationState.Instance.Logger.EnableFsAccessLog.Event += ReloadEnableFsAccessLog; ConfigurationState.Instance.Logger.FilteredClasses.Event += ReloadFilteredClasses; ConfigurationState.Instance.Logger.EnableFileLog.Event += ReloadFileLogger; + ConfigurationState.Instance.Logger.DisableLogFileSizeLimit.Event += ReloadDisableLogFileSizeLimit; } private static void ReloadEnableDebug(object sender, ReactiveEventArgs e) @@ -78,6 +79,14 @@ namespace Ryujinx.UI.Common.Configuration } } + private static void ReloadDisableLogFileSizeLimit(object sender, ReactiveEventArgs e) + { + //TODO: add function to add or remove the file size limit during runtime. + //NOTE: Is this needed? If we want it, we would need to add a function on ILogTarget to do the job + //or some mechanism to directly access the FileLogTarget via AsyncLogTargetWrapper. For now, + //changes to this value only take effect after restart (which is probably what the user wants anyway). + } + private static void ReloadFileLogger(object sender, ReactiveEventArgs e) { if (e.NewValue) @@ -98,8 +107,10 @@ namespace Ryujinx.UI.Common.Configuration return; } + bool limitsFileSize = !ConfigurationState.Instance.Logger.DisableLogFileSizeLimit; + Logger.AddTarget(new AsyncLogTargetWrapper( - new FileLogTarget("file", logFile), + new FileLogTarget("file", logFile, limitsFileSize), 1000, AsyncLogTargetOverflowAction.Block )); diff --git a/src/Ryujinx/Assets/Locales/en_US.json b/src/Ryujinx/Assets/Locales/en_US.json index 8df0f96a14..8a7c34ab94 100644 --- a/src/Ryujinx/Assets/Locales/en_US.json +++ b/src/Ryujinx/Assets/Locales/en_US.json @@ -189,6 +189,7 @@ "SettingsTabLoggingGraphicsBackendLogLevelPerformance": "Slowdowns", "SettingsTabLoggingGraphicsBackendLogLevelAll": "All", "SettingsTabLoggingEnableDebugLogs": "Enable Debug Logs", + "SettingsTabLoggingDisableLogFileSizeLimit": "Disable Log File Size Limit", "SettingsTabInput": "Input", "SettingsTabInputEnableDockedMode": "Docked Mode", "SettingsTabInputDirectKeyboardAccess": "Direct Keyboard Access", @@ -596,6 +597,7 @@ "DeveloperOptionTooltip": "Use with care", "OpenGlLogLevel": "Requires appropriate log levels enabled", "DebugLogTooltip": "Prints debug log messages in the console.\n\nOnly use this if specifically instructed by a staff member, as it will make logs difficult to read and worsen emulator performance.", + "DisableLogFileSizeTooltip": "Removes the 500MB limit on log file size.", "LoadApplicationFileTooltip": "Open a file explorer to choose a Switch compatible file to load", "LoadApplicationFolderTooltip": "Open a file explorer to choose a Switch compatible, unpacked application to load", "OpenRyujinxFolderTooltip": "Open Ryujinx filesystem folder", diff --git a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs index 70e5fa5c74..58d3e87d72 100644 --- a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs @@ -156,6 +156,7 @@ namespace Ryujinx.Ava.UI.ViewModels public bool EnableGuest { get; set; } public bool EnableFsAccessLog { get; set; } public bool EnableDebug { get; set; } + public bool DisableLogFileSizeLimit { get; set; } public bool IsOpenAlEnabled { get; set; } public bool IsSoundIoEnabled { get; set; } public bool IsSDL2Enabled { get; set; } @@ -471,6 +472,7 @@ namespace Ryujinx.Ava.UI.ViewModels EnableFsAccessLog = config.Logger.EnableFsAccessLog; FsGlobalAccessLogMode = config.System.FsGlobalAccessLogMode; OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value; + DisableLogFileSizeLimit = config.Logger.DisableLogFileSizeLimit; MultiplayerModeIndex = (int)config.Multiplayer.Mode.Value; } @@ -577,6 +579,7 @@ namespace Ryujinx.Ava.UI.ViewModels config.Logger.EnableFsAccessLog.Value = EnableFsAccessLog; config.System.FsGlobalAccessLogMode.Value = FsGlobalAccessLogMode; config.Logger.GraphicsDebugLevel.Value = (GraphicsDebugLevel)OpenglDebugLevel; + config.Logger.DisableLogFileSizeLimit.Value = DisableLogFileSizeLimit; config.Multiplayer.LanInterfaceId.Value = _networkInterfaces[NetworkInterfaceList[NetworkInterfaceIndex]]; config.Multiplayer.Mode.Value = (MultiplayerMode)MultiplayerModeIndex; diff --git a/src/Ryujinx/UI/Views/Settings/SettingsLoggingView.axaml b/src/Ryujinx/UI/Views/Settings/SettingsLoggingView.axaml index 0fc9ea1bb1..d4e9383ed4 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsLoggingView.axaml +++ b/src/Ryujinx/UI/Views/Settings/SettingsLoggingView.axaml @@ -74,6 +74,10 @@ ToolTip.Tip="{locale:Locale DebugLogTooltip}"> + + + - \ No newline at end of file +