Logging level can be set in the UI (immediately applied)

Logging level is set from config on startup as well
pull/6/head
Mark McDowall 11 years ago
parent 13b71bdeb7
commit 69d067d2c0

@ -31,13 +31,42 @@ namespace NzbDrone.Core.Instrumentation
public void Reconfigure() public void Reconfigure()
{ {
var logLevel = _configFileProvider.LogLevel; var minimumLogLevel = LogLevel.FromString(_configFileProvider.LogLevel);
var rules = LogManager.Configuration.LoggingRules; var rules = LogManager.Configuration.LoggingRules;
var rollingFileLogger = rules.Single(s => s.Targets.Any(t => t.Name == "rollingFileLogger")); var rollingFileLogger = rules.Single(s => s.Targets.Any(t => t.Name == "rollingFileLogger"));
rollingFileLogger.EnableLoggingForLevel(LogLevel.Trace); 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<LogLevel> GetLogLevels()
{
return new List<LogLevel>
{
LogLevel.Trace,
LogLevel.Debug,
LogLevel.Info,
LogLevel.Warn,
LogLevel.Error,
LogLevel.Fatal
};
} }
public void HandleAsync(ConfigFileSavedEvent message) public void HandleAsync(ConfigFileSavedEvent message)

@ -70,4 +70,24 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset>
<legend>Logging</legend>
<div class="control-group">
<label class="control-label">Log Level</label>
<div class="controls">
<select name="logLevel">
<option value="Trace">Trace</option>
<option value="Debug">Debug</option>
<option value="Info">Info</option>
</select>
<span>
<i class="icon-form-danger" title="Trace and Debug logging should only be enabled temporarily"/>
</span>
</div>
</div>
</fieldset>
</div> </div>

Loading…
Cancel
Save