mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-02 13:14:28 -04:00
* Introduced a lock for DB work during the scan to hopefully reduce the concurrency issues * Don't allow multiple theme scans to occur * Fixed bulk actions not having all actions due to nested actionable menu changes * Refactored the Scan loop to be synchronous to avoid any issues. After first loop, no real performance issues. * Updated the LibraryWatcher when under many internal buffer full issues, to suspend watching for a full hour, to allow whatever downloading to complete. * Removed Semaphore as it's not needed anymore * Updated the output for logger to explicitly say from Kavita (if you're pushing to Seq) * Fixed a broken test * Fixed ReleaseYear not populating due to a change from a contributor around how to populate ReleaseYear. * Ensure when scan folder runs, that we don't double enqueue the same tasks. * Fixed user settings not loading the correct tab * Changed the Release Year -> Release * Added more refresh hooks in reader to hopefully ensure faster refreshes * Reset images between chapter loads to help flush image faster. Don't show broken image icon when an image is still loading. * Fixed the prefetcher not properly loading the correct images and hence, allowing a bit of lag between chapter loads. * Code smells
101 lines
4.8 KiB
C#
101 lines
4.8 KiB
C#
using System.IO;
|
|
using API.Services;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Serilog;
|
|
using Serilog.Core;
|
|
using Serilog.Events;
|
|
using Serilog.Formatting.Display;
|
|
|
|
namespace API.Logging;
|
|
|
|
/// <summary>
|
|
/// This class represents information for configuring Logging in the Application. Only a high log level is exposed and Kavita
|
|
/// controls the underlying log levels for different loggers in ASP.NET
|
|
/// </summary>
|
|
public static class LogLevelOptions
|
|
{
|
|
public const string LogFile = "config/logs/kavita.log";
|
|
public const bool LogRollingEnabled = true;
|
|
/// <summary>
|
|
/// Controls the Logging Level of the Application
|
|
/// </summary>
|
|
private static readonly LoggingLevelSwitch LogLevelSwitch = new ();
|
|
/// <summary>
|
|
/// Controls Microsoft's Logging Level
|
|
/// </summary>
|
|
private static readonly LoggingLevelSwitch MicrosoftLogLevelSwitch = new (LogEventLevel.Error);
|
|
/// <summary>
|
|
/// Controls Microsoft.Hosting.Lifetime's Logging Level
|
|
/// </summary>
|
|
private static readonly LoggingLevelSwitch MicrosoftHostingLifetimeLogLevelSwitch = new (LogEventLevel.Error);
|
|
/// <summary>
|
|
/// Controls Hangfire's Logging Level
|
|
/// </summary>
|
|
private static readonly LoggingLevelSwitch HangfireLogLevelSwitch = new (LogEventLevel.Error);
|
|
/// <summary>
|
|
/// Controls Microsoft.AspNetCore.Hosting.Internal.WebHost's Logging Level
|
|
/// </summary>
|
|
private static readonly LoggingLevelSwitch AspNetCoreLogLevelSwitch = new (LogEventLevel.Error);
|
|
|
|
public static LoggerConfiguration CreateConfig(LoggerConfiguration configuration)
|
|
{
|
|
const string outputTemplate = "[Kavita] [{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} {CorrelationId} {ThreadId}] [{Level}] {SourceContext} {Message:lj}{NewLine}{Exception}";
|
|
return configuration
|
|
.MinimumLevel
|
|
.ControlledBy(LogLevelSwitch)
|
|
.MinimumLevel.Override("Microsoft", MicrosoftLogLevelSwitch)
|
|
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", MicrosoftHostingLifetimeLogLevelSwitch)
|
|
.MinimumLevel.Override("Hangfire", HangfireLogLevelSwitch)
|
|
.MinimumLevel.Override("Microsoft.AspNetCore.Hosting.Internal.WebHost", AspNetCoreLogLevelSwitch)
|
|
// Suppress noisy loggers that add no value
|
|
.MinimumLevel.Override("Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware", LogEventLevel.Error)
|
|
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Error)
|
|
.Enrich.FromLogContext()
|
|
.Enrich.WithThreadId()
|
|
.WriteTo.Console(new MessageTemplateTextFormatter(outputTemplate))
|
|
.WriteTo.File(LogFile,
|
|
shared: true,
|
|
rollingInterval: RollingInterval.Day,
|
|
outputTemplate: outputTemplate);
|
|
}
|
|
|
|
public static void SwitchLogLevel(string level)
|
|
{
|
|
switch (level)
|
|
{
|
|
case "Debug":
|
|
LogLevelSwitch.MinimumLevel = LogEventLevel.Debug;
|
|
MicrosoftLogLevelSwitch.MinimumLevel = LogEventLevel.Warning; // This is DB output information, Inf shows the SQL
|
|
MicrosoftHostingLifetimeLogLevelSwitch.MinimumLevel = LogEventLevel.Information;
|
|
AspNetCoreLogLevelSwitch.MinimumLevel = LogEventLevel.Warning;
|
|
break;
|
|
case "Information":
|
|
LogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
MicrosoftLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
MicrosoftHostingLifetimeLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
AspNetCoreLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
break;
|
|
case "Trace":
|
|
LogLevelSwitch.MinimumLevel = LogEventLevel.Verbose;
|
|
MicrosoftLogLevelSwitch.MinimumLevel = LogEventLevel.Information;
|
|
MicrosoftHostingLifetimeLogLevelSwitch.MinimumLevel = LogEventLevel.Debug;
|
|
AspNetCoreLogLevelSwitch.MinimumLevel = LogEventLevel.Information;
|
|
break;
|
|
case "Warning":
|
|
LogLevelSwitch.MinimumLevel = LogEventLevel.Warning;
|
|
MicrosoftLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
MicrosoftHostingLifetimeLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
AspNetCoreLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
break;
|
|
case "Critical":
|
|
LogLevelSwitch.MinimumLevel = LogEventLevel.Fatal;
|
|
MicrosoftLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
MicrosoftHostingLifetimeLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
AspNetCoreLogLevelSwitch.MinimumLevel = LogEventLevel.Error;
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|