mirror of https://github.com/Jackett/Jackett
Update Logging
This commit is contained in:
parent
cd65ec7a71
commit
012f5f05cc
|
@ -96,7 +96,7 @@ namespace Jackett.Server.Controllers
|
||||||
serverConfig.RuntimeSettings.BasePath = serverService.BasePath();
|
serverConfig.RuntimeSettings.BasePath = serverService.BasePath();
|
||||||
configService.SaveConfig(serverConfig);
|
configService.SaveConfig(serverConfig);
|
||||||
|
|
||||||
Initialisation.SetLogLevel(logging ? LogLevel.Debug : LogLevel.Info);
|
Helper.SetLogLevel(logging ? LogLevel.Debug : LogLevel.Info);
|
||||||
serverConfig.RuntimeSettings.TracingEnabled = logging;
|
serverConfig.RuntimeSettings.TracingEnabled = logging;
|
||||||
|
|
||||||
if (omdbApiKey != serverConfig.OmdbApiKey)
|
if (omdbApiKey != serverConfig.OmdbApiKey)
|
||||||
|
|
|
@ -133,5 +133,28 @@ namespace Jackett.Server
|
||||||
builder.RegisterInstance(logger).SingleInstance();
|
builder.RegisterInstance(logger).SingleInstance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetLogLevel(LogLevel level)
|
||||||
|
{
|
||||||
|
foreach (var rule in LogManager.Configuration.LoggingRules)
|
||||||
|
{
|
||||||
|
if (level == LogLevel.Debug)
|
||||||
|
{
|
||||||
|
if (!rule.Levels.Contains(LogLevel.Debug))
|
||||||
|
{
|
||||||
|
rule.EnableLoggingForLevel(LogLevel.Debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (rule.Levels.Contains(LogLevel.Debug))
|
||||||
|
{
|
||||||
|
rule.DisableLoggingForLevel(LogLevel.Debug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LogManager.ReconfigExistingLoggers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
using Jackett.Common;
|
using Jackett.Common.Models.Config;
|
||||||
using Jackett.Common.Models.Config;
|
|
||||||
using Jackett.Common.Services;
|
|
||||||
using Jackett.Common.Services.Interfaces;
|
using Jackett.Common.Services.Interfaces;
|
||||||
using Jackett.Common.Utils;
|
using Jackett.Common.Utils;
|
||||||
using Jackett.Server.Services;
|
using Jackett.Server.Services;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Config;
|
|
||||||
using NLog.Targets;
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
@ -16,7 +11,6 @@ namespace Jackett.Server
|
||||||
{
|
{
|
||||||
public static class Initialisation
|
public static class Initialisation
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void ProcessSettings(RuntimeSettings runtimeSettings, Logger logger)
|
public static void ProcessSettings(RuntimeSettings runtimeSettings, Logger logger)
|
||||||
{
|
{
|
||||||
if (runtimeSettings.ClientOverride != "httpclient" && runtimeSettings.ClientOverride != "httpclient2")
|
if (runtimeSettings.ClientOverride != "httpclient" && runtimeSettings.ClientOverride != "httpclient2")
|
||||||
|
@ -180,63 +174,5 @@ namespace Jackett.Server
|
||||||
{
|
{
|
||||||
processService.StartProcessAndLog("netsh.exe", args);
|
processService.StartProcessAndLog("netsh.exe", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LoggingConfiguration SetupLogging(RuntimeSettings settings)
|
|
||||||
{
|
|
||||||
var logFileName = settings.CustomLogFileName ?? "log.txt";
|
|
||||||
var logLevel = settings.TracingEnabled ? NLog.LogLevel.Debug : NLog.LogLevel.Info;
|
|
||||||
// Add custom date time format renderer as the default is too long
|
|
||||||
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("simpledatetime", typeof(SimpleDateTimeRenderer));
|
|
||||||
|
|
||||||
var logConfig = new LoggingConfiguration();
|
|
||||||
var logFile = new FileTarget();
|
|
||||||
logConfig.AddTarget("file", logFile);
|
|
||||||
logFile.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
|
|
||||||
logFile.FileName = Path.Combine(settings.DataFolder, logFileName);
|
|
||||||
logFile.ArchiveFileName = "log.{#####}.txt";
|
|
||||||
logFile.ArchiveAboveSize = 500000;
|
|
||||||
logFile.MaxArchiveFiles = 5;
|
|
||||||
logFile.KeepFileOpen = false;
|
|
||||||
logFile.ArchiveNumbering = ArchiveNumberingMode.DateAndSequence;
|
|
||||||
var logFileRule = new LoggingRule("*", logLevel, logFile);
|
|
||||||
logConfig.LoggingRules.Add(logFileRule);
|
|
||||||
|
|
||||||
var logConsole = new ColoredConsoleTarget();
|
|
||||||
logConfig.AddTarget("console", logConsole);
|
|
||||||
|
|
||||||
logConsole.Layout = "${simpledatetime} ${level} ${message} ${exception:format=ToString}";
|
|
||||||
var logConsoleRule = new LoggingRule("*", logLevel, logConsole);
|
|
||||||
logConfig.LoggingRules.Add(logConsoleRule);
|
|
||||||
|
|
||||||
var logService = new LogCacheService();
|
|
||||||
logConfig.AddTarget("service", logService);
|
|
||||||
var serviceRule = new LoggingRule("*", logLevel, logService);
|
|
||||||
logConfig.LoggingRules.Add(serviceRule);
|
|
||||||
|
|
||||||
return logConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetLogLevel(LogLevel level)
|
|
||||||
{
|
|
||||||
foreach (var rule in LogManager.Configuration.LoggingRules)
|
|
||||||
{
|
|
||||||
if (level == LogLevel.Debug)
|
|
||||||
{
|
|
||||||
if (!rule.Levels.Contains(LogLevel.Debug))
|
|
||||||
{
|
|
||||||
rule.EnableLoggingForLevel(LogLevel.Debug);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (rule.Levels.Contains(LogLevel.Debug))
|
|
||||||
{
|
|
||||||
rule.DisableLoggingForLevel(LogLevel.Debug);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LogManager.ReconfigExistingLoggers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace Jackett.Server
|
||||||
runtimeDictionary = GetValues(Settings);
|
runtimeDictionary = GetValues(Settings);
|
||||||
});
|
});
|
||||||
|
|
||||||
LogManager.Configuration = Initialisation.SetupLogging(Settings);
|
LogManager.Configuration = LoggingSetup.GetLoggingConfiguration(Settings);
|
||||||
Logger logger = LogManager.GetCurrentClassLogger();
|
Logger logger = LogManager.GetCurrentClassLogger();
|
||||||
logger.Info("Starting Jackett v" + EnvironmentUtil.JackettVersion);
|
logger.Info("Starting Jackett v" + EnvironmentUtil.JackettVersion);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue