From 69d067d2c07017184e60ae48bab2f6f7e25afda2 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 24 Jul 2013 18:03:20 -0700 Subject: [PATCH] Logging level can be set in the UI (immediately applied) Logging level is set from config on startup as well --- .../Instrumentation/SetLoggingLevel.cs | 33 +++++++++++++++++-- UI/Settings/General/GeneralTemplate.html | 20 +++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs b/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs index 6067146b6..bc3f0e3d7 100644 --- a/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs +++ b/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs @@ -31,13 +31,42 @@ namespace NzbDrone.Core.Instrumentation public void Reconfigure() { - var logLevel = _configFileProvider.LogLevel; + var minimumLogLevel = LogLevel.FromString(_configFileProvider.LogLevel); var rules = LogManager.Configuration.LoggingRules; var rollingFileLogger = rules.Single(s => s.Targets.Any(t => t.Name == "rollingFileLogger")); rollingFileLogger.EnableLoggingForLevel(LogLevel.Trace); - var test = 1; + SetMinimumLogLevel(rollingFileLogger, minimumLogLevel); + } + + private void SetMinimumLogLevel(LoggingRule rule, LogLevel minimumLogLevel) + { + foreach (var logLevel in GetLogLevels()) + { + if (logLevel < minimumLogLevel) + { + rule.DisableLoggingForLevel(logLevel); + } + + else + { + rule.EnableLoggingForLevel(logLevel); + } + } + } + + private List GetLogLevels() + { + return new List + { + LogLevel.Trace, + LogLevel.Debug, + LogLevel.Info, + LogLevel.Warn, + LogLevel.Error, + LogLevel.Fatal + }; } public void HandleAsync(ConfigFileSavedEvent message) diff --git a/UI/Settings/General/GeneralTemplate.html b/UI/Settings/General/GeneralTemplate.html index 2650cca79..6325f37c1 100644 --- a/UI/Settings/General/GeneralTemplate.html +++ b/UI/Settings/General/GeneralTemplate.html @@ -70,4 +70,24 @@ + +
+ Logging + +
+ + +
+ + + + + +
+
+