fix saving the log level

This commit is contained in:
Drewster727 2016-04-17 21:58:34 -05:00
parent 5dc39b9b3a
commit 84edd6636d
6 changed files with 69 additions and 8 deletions

View file

@ -78,6 +78,7 @@ namespace PlexRequests.UI
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
container.Register<ISettingsService<PushoverNotificationSettings>, SettingsServiceV2<PushoverNotificationSettings>>();
container.Register<ISettingsService<HeadphonesSettings>, SettingsServiceV2<HeadphonesSettings>>();
container.Register<ISettingsService<LogSettings>, SettingsServiceV2<LogSettings>>();
// Repo's
container.Register<IRepository<LogEntity>, GenericRepository<LogEntity>>();

View file

@ -68,6 +68,7 @@ namespace PlexRequests.UI.Modules
private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; }
private ISettingsService<PushoverNotificationSettings> PushoverService { get; }
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
private ISettingsService<LogSettings> LogService { get; }
private IPlexApi PlexApi { get; }
private ISonarrApi SonarrApi { get; }
private IPushbulletApi PushbulletApi { get; }
@ -95,6 +96,7 @@ namespace PlexRequests.UI.Modules
IRepository<LogEntity> logsRepo,
INotificationService notify,
ISettingsService<HeadphonesSettings> headphones,
ISettingsService<LogSettings> logs,
ICacheProvider cache) : base("admin")
{
PrService = prService;
@ -114,6 +116,7 @@ namespace PlexRequests.UI.Modules
PushoverApi = pushoverApi;
NotificationService = notify;
HeadphonesService = headphones;
LogService = logs;
Cache = cache;
#if !DEBUG
@ -637,8 +640,16 @@ namespace PlexRequests.UI.Modules
private Response UpdateLogLevels(int level)
{
var settings = LogService.GetSettings();
// apply the level
var newLevel = LogLevel.FromOrdinal(level);
LoggingHelper.ReconfigureLogLevel(newLevel);
//save the log settings
settings.Level = level;
LogService.SaveSettings(settings);
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}"});
}

View file

@ -25,7 +25,6 @@
// ************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using Microsoft.Owin.Hosting;
@ -42,8 +41,6 @@ using PlexRequests.Store.Repository;
using System.Diagnostics;
using FluentScheduler;
using PlexRequests.Services;
using PlexRequests.UI.Jobs;
namespace PlexRequests.UI
@ -91,6 +88,7 @@ namespace PlexRequests.UI
var cn = s.SetupDb(baseUrl);
s.CacheQualityProfiles();
ConfigureTargets(cn);
SetupLogging();
if (port == -1)
port = GetStartupPort();
@ -157,6 +155,17 @@ namespace PlexRequests.UI
LoggingHelper.ConfigureLogging(connectionString);
}
private static void SetupLogging()
{
var settingsService = new SettingsServiceV2<LogSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
var logSettings = settingsService.GetSettings();
if (logSettings != null)
{
LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
}
}
private static void SetupSchedulers()
{
TaskManager.TaskFactory = new PlexTaskFactory();

View file

@ -76,11 +76,14 @@
url: logUrl,
dataType: "json",
success: function (response) {
$("#select > option").each(function (level) {
if (response[0] == level.value) {
$('#' + level.target.id).prop("selected", "selected");
}
});
if (response && response.length > 0) {
$("#selected > option").each(function (level) {
var $opt = $(this);
if (response[0].ordinal == level) {
$opt.prop("selected", "selected");
}
});
}
},
error: function (e) {
console.log(e);