From df035a069d20009a7987c833678d443d4c3a1646 Mon Sep 17 00:00:00 2001 From: Wendell Jones Date: Wed, 8 Jul 2026 15:44:42 -0400 Subject: [PATCH] fix logging --- .../Extensions/ServiceCollectionExtensions.cs | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs b/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs index 1ec8a676..30b8f56c 100644 --- a/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs +++ b/Jellyfin.Server.Implementations/Extensions/ServiceCollectionExtensions.cs @@ -18,6 +18,7 @@ using MediaBrowser.Controller.Configuration; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using JellyfinDbProviderFactory = System.Func; /// @@ -25,6 +26,35 @@ using JellyfinDbProviderFactory = System.Func public static class ServiceCollectionExtensions { + /// + /// Determines whether detailed EF Core logging should be enabled based on the configured log level. + /// + /// The application configuration. + /// True if the log level for Microsoft.EntityFrameworkCore.Database.Command is Debug or lower; otherwise false. + private static bool ShouldEnableDetailedEFCoreLogging(IConfiguration configuration) + { + // Check if detailed EF Core logging is explicitly enabled in configuration + // Read the log level override for Entity Framework Core command logging + var efCoreLogLevelString = configuration["Serilog:MinimumLevel:Override:Microsoft.EntityFrameworkCore.Database.Command"]; + + if (string.IsNullOrWhiteSpace(efCoreLogLevelString)) + { + // If not explicitly set, check the default minimum level + efCoreLogLevelString = configuration["Serilog:MinimumLevel:Default"] ?? "Information"; + } + + // Parse the log level string to LogLevel enum + if (Enum.TryParse(efCoreLogLevelString, ignoreCase: true, out var logLevel)) + { + // Enable detailed logging if the level is Debug or lower (more verbose) + // LogLevel order: Trace=0, Debug=1, Information=2, Warning=3, Error=4, Critical=5, None=6 + return logLevel <= LogLevel.Debug; + } + + // Default to false if we can't parse the log level + return false; + } + private static IEnumerable DatabaseProviderTypes() { yield return typeof(PostgresDatabaseProvider); @@ -170,9 +200,15 @@ public static class ServiceCollectionExtensions lockingBehavior.Initialise(opt); var loggerFactory = serviceProvider.GetService(); - opt.UseLoggerFactory(loggerFactory) - .EnableSensitiveDataLogging() - .EnableDetailedErrors(); + opt.UseLoggerFactory(loggerFactory); + + // Only enable sensitive data logging and detailed errors if the EF Core command log level + // is set to Debug or lower, respecting the logging configuration from logging.json + if (ShouldEnableDetailedEFCoreLogging(configuration)) + { + opt.EnableSensitiveDataLogging() + .EnableDetailedErrors(); + } }); return serviceCollection;