Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make debug logs optional #569

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RetroBar/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<setting name="TaskbarScale" serializeAs="String">
<value>1</value>
</setting>
<setting name="DebugLogging" serializeAs="String">
<value>False</value>
</setting>
</RetroBar.Properties.Settings>
</userSettings>
</configuration>
1 change: 1 addition & 0 deletions RetroBar/Languages/English.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<s:String x:Key="taskbar_scale_1x">100%</s:String>
<s:String x:Key="taskbar_scale_2x">200%</s:String>
<s:String x:Key="taskbar_scale_current">Current setting: {0}%</s:String>
<s:String x:Key="debug_logging">Enable debug logging</s:String>
<s:String x:Key="ok_dialog">OK</s:String>

<s:String x:Key="customize_notifications">Customize Notifications</s:String>
Expand Down
12 changes: 12 additions & 0 deletions RetroBar/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions RetroBar/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
<Setting Name="TaskbarScale" Type="System.Double" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
<Setting Name="DebugLogging" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
4 changes: 4 additions & 0 deletions RetroBar/PropertiesWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@
IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=UseSoftwareRendering, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{DynamicResource use_software_rendering}" />
</CheckBox>
<CheckBox x:Name="cbDebugLogging"
IsChecked="{Binding Source={x:Static Settings:Settings.Instance}, Path=DebugLogging, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{DynamicResource debug_logging}" />
</CheckBox>
</StackPanel>
<GroupBox Header="{DynamicResource multiple_displays}"
Margin="0,0,0,10">
Expand Down
18 changes: 16 additions & 2 deletions RetroBar/Utilities/ManagedShellLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,31 @@ class ManagedShellLogger : IDisposable
private string _logPath = Path.Combine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "RetroBar"), "Logs");
private string _logName = DateTime.Now.ToString("yyyy-MM-dd_HHmmssfff");
private string _logExt = "log";
private LogSeverity _logSeverity = LogSeverity.Debug;
private TimeSpan _logRetention = new TimeSpan(7, 0, 0);
private FileLog _fileLog;

public ManagedShellLogger()
{
SetupLogging();
Settings.Instance.PropertyChanged += Settings_PropertyChanged;
}

private void Settings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "DebugLogging")
{
SetSeverity();
}
}

private void SetSeverity()
{
ShellLogger.Severity = Settings.Instance.DebugLogging ? LogSeverity.Debug : LogSeverity.Info;
}

private void SetupLogging()
{
ShellLogger.Severity = _logSeverity;
SetSeverity();

SetupFileLog();

Expand Down Expand Up @@ -64,6 +77,7 @@ private void DeleteOldLogFiles()

public void Dispose()
{
Settings.Instance.PropertyChanged -= Settings_PropertyChanged;
_fileLog?.Dispose();
}
}
Expand Down
15 changes: 15 additions & 0 deletions RetroBar/Utilities/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ public double TaskbarScale
}
}
}

public bool DebugLogging
{
get
{
return settings.DebugLogging;
}
set
{
if (settings.DebugLogging != value)
{
settings.DebugLogging = value;
}
}
}
#endregion

#region Helpers
Expand Down