Skip to content

Commit

Permalink
Closes #3861 -- introduces new setting that isn't UI-visible but allo…
Browse files Browse the repository at this point in the history
…w us to ship Rubberduck with Trace as the default logging level. If the user do not edit it, at the shutdown of the Rubberduck, the log level will be changed to None.
  • Loading branch information
bclothier committed Oct 18, 2018
1 parent 8d26793 commit eb9353a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
20 changes: 20 additions & 0 deletions Rubberduck.Core/App.cs
Expand Up @@ -105,6 +105,24 @@ private void UpdateLoggingLevel()
LogLevelHelper.SetMinimumLogLevel(LogLevel.FromOrdinal(_config.UserSettings.GeneralSettings.MinimumLogLevel));
}

/// <summary>
/// Ensure that log level is changed to "none" after a successful
/// run of Rubberduck for first time. By default, we ship with
/// log level set to Trace (0) but once it's installed and has
/// ran without problem, it should be set to None (6)
/// </summary>
private void UpdateLoggingLevelOnShutdown()
{
if (_config.UserSettings.GeneralSettings.UserEditedLogLevel ||
_config.UserSettings.GeneralSettings.MinimumLogLevel != LogLevel.Trace.Ordinal)
{
return;
}

_config.UserSettings.GeneralSettings.MinimumLogLevel = LogLevel.Off.Ordinal;
_configService.SaveConfiguration(_config);
}

public void Startup()
{
EnsureLogFolderPathExists();
Expand All @@ -131,6 +149,8 @@ public void Shutdown()
{
Debug.WriteLine("App calling Hooks.Detach.");
_hooks.Detach();

UpdateLoggingLevelOnShutdown();
}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.Core/Properties/Settings.Designer.cs

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

3 changes: 2 additions & 1 deletion Rubberduck.Core/Properties/Settings.settings
Expand Up @@ -178,7 +178,8 @@
&lt;IsSmartIndenterPrompted&gt;false&lt;/IsSmartIndenterPrompted&gt;
&lt;IsAutoSaveEnabled&gt;false&lt;/IsAutoSaveEnabled&gt;
&lt;AutoSavePeriod&gt;10&lt;/AutoSavePeriod&gt;
&lt;MinimumLogLevel&gt;6&lt;/MinimumLogLevel&gt;
&lt;UserEditedLogLevel&gt;false&lt;/UserEditedLogLevel&gt;
&lt;MinimumLogLevel&gt;0&lt;/MinimumLogLevel&gt;
&lt;EnableExperimentalFeatures /&gt;
&lt;/GeneralSettings&gt;</Value>
</Setting>
Expand Down
3 changes: 2 additions & 1 deletion Rubberduck.Core/Rubberduck.Core.csproj
Expand Up @@ -123,9 +123,10 @@
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>PublicSettingsSingleFileGenerator</Generator>
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions Rubberduck.Core/Settings/GeneralSettings.cs
Expand Up @@ -16,6 +16,7 @@ public interface IGeneralSettings
bool IsSmartIndenterPrompted { get; set; }
bool IsAutoSaveEnabled { get; set; }
int AutoSavePeriod { get; set; }
bool UserEditedLogLevel { get; set; }
int MinimumLogLevel { get; set; }
List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; }
}
Expand All @@ -32,6 +33,8 @@ public class GeneralSettings : IGeneralSettings, IEquatable<GeneralSettings>
public bool IsAutoSaveEnabled { get; set; }
public int AutoSavePeriod { get; set; }

public bool UserEditedLogLevel { get; set; }

private int _logLevel;
public int MinimumLogLevel
{
Expand Down Expand Up @@ -73,6 +76,7 @@ public bool Equals(GeneralSettings other)
IsSmartIndenterPrompted == other.IsSmartIndenterPrompted &&
IsAutoSaveEnabled == other.IsAutoSaveEnabled &&
AutoSavePeriod == other.AutoSavePeriod &&
UserEditedLogLevel == other.UserEditedLogLevel &&
MinimumLogLevel == other.MinimumLogLevel &&
EnableExperimentalFeatures.All(a => other.EnableExperimentalFeatures.Contains(a)) &&
EnableExperimentalFeatures.Count == other.EnableExperimentalFeatures.Count;
Expand Down
8 changes: 6 additions & 2 deletions Rubberduck.Core/UI/Settings/GeneralSettingsViewModel.cs
Expand Up @@ -200,6 +200,7 @@ public DelimiterOptions Delimiter

public ObservableCollection<MinimumLogLevel> LogLevels { get; set; }
private MinimumLogLevel _selectedLogLevel;
private bool _userEditedLogLevel;

public MinimumLogLevel SelectedLogLevel
{
Expand All @@ -208,6 +209,7 @@ public MinimumLogLevel SelectedLogLevel
{
if (!Equals(_selectedLogLevel, value))
{
_userEditedLogLevel = true;
_selectedLogLevel = value;
OnPropertyChanged();
}
Expand Down Expand Up @@ -243,7 +245,8 @@ private Rubberduck.Settings.GeneralSettings GetCurrentGeneralSettings()
IsSmartIndenterPrompted = _indenterPrompted,
IsAutoSaveEnabled = AutoSaveEnabled,
AutoSavePeriod = AutoSavePeriod,
MinimumLogLevel = SelectedLogLevel.Ordinal,
UserEditedLogLevel = _userEditedLogLevel,
MinimumLogLevel = _selectedLogLevel.Ordinal,
EnableExperimentalFeatures = ExperimentalFeatures
};
}
Expand All @@ -258,7 +261,8 @@ private void TransferSettingsToView(IGeneralSettings general, IHotkeySettings ho
_indenterPrompted = general.IsSmartIndenterPrompted;
AutoSaveEnabled = general.IsAutoSaveEnabled;
AutoSavePeriod = general.AutoSavePeriod;
SelectedLogLevel = LogLevels.First(l => l.Ordinal == general.MinimumLogLevel);
_userEditedLogLevel = general.UserEditedLogLevel;
_selectedLogLevel = LogLevels.First(l => l.Ordinal == general.MinimumLogLevel);

ExperimentalFeatures = _experimentalFeatureTypes
.SelectMany(s => s.CustomAttributes.Where(a => a.ConstructorArguments.Any()).Select(a => (string)a.ConstructorArguments.First().Value))
Expand Down
3 changes: 2 additions & 1 deletion Rubberduck.Core/app.config
Expand Up @@ -228,7 +228,8 @@
<IsSmartIndenterPrompted>false</IsSmartIndenterPrompted>
<IsAutoSaveEnabled>false</IsAutoSaveEnabled>
<AutoSavePeriod>10</AutoSavePeriod>
<MinimumLogLevel>6</MinimumLogLevel>
<UserEditedLogLevel>false</UserEditedLogLevel>
<MinimumLogLevel>0</MinimumLogLevel>
<EnableExperimentalFeatures />
</GeneralSettings>
</value>
Expand Down

0 comments on commit eb9353a

Please sign in to comment.