From b2ce70987c2f724436514e8f91f9f455be7d13ff Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 30 Nov 2022 22:07:34 +0100 Subject: [PATCH] Change log level for slow HTTP responses from WRN TO DBG The added log level check is there because Request.GetDisplayUrl() is a pretty expensive call, creating a StringBuilder and string which doesn't need to happen on most installs where debug logging is disabled --- Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs b/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs index 1c25696cd1..65b64da4f1 100644 --- a/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs +++ b/Jellyfin.Server/Middleware/ResponseTimeMiddleware.cs @@ -47,9 +47,10 @@ namespace Jellyfin.Server.Middleware context.Response.OnStarting(() => { watch.Stop(); - if (enableWarning && watch.ElapsedMilliseconds > warningThreshold) + var responseTimeForCompleteRequest = watch.ElapsedMilliseconds; + if (enableWarning && responseTimeForCompleteRequest > warningThreshold && _logger.IsEnabled(LogLevel.Debug)) { - _logger.LogWarning( + _logger.LogDebug( "Slow HTTP Response from {Url} to {RemoteIp} in {Elapsed:g} with Status Code {StatusCode}", context.Request.GetDisplayUrl(), context.GetNormalizedRemoteIp(), @@ -57,7 +58,6 @@ namespace Jellyfin.Server.Middleware context.Response.StatusCode); } - var responseTimeForCompleteRequest = watch.ElapsedMilliseconds; context.Response.Headers[ResponseHeaderResponseTime] = responseTimeForCompleteRequest.ToString(CultureInfo.InvariantCulture); return Task.CompletedTask; });