From ab2b926de0180023cd73f77d8ab68ff2158f660c Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Mon, 4 Aug 2025 14:51:13 +0000 Subject: [PATCH] add searching log category (#2251) --- CHANGELOG.md | 1 + .../Commands/UpdateLoggingSettingsHandler.cs | 5 +++++ .../Configuration/LoggingSettingsViewModel.cs | 1 + .../Queries/GetLoggingSettingsHandler.cs | 4 ++++ ErsatzTV.Core/Domain/ConfigElementKey.cs | 1 + ErsatzTV.Core/LoggingLevelSwitches.cs | 2 ++ .../Search/SearchQueryParser.cs | 16 ++++++++-------- ErsatzTV/Pages/Settings/LoggingSettings.razor | 11 +++++++++++ ErsatzTV/Program.cs | 4 ++++ 9 files changed, 37 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0fdc6c46..23d31f28e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Always tell ffmpeg to stop encoding with a specific duration - This was removed to try to improve transitions with ffmpeg 7.x, but has been causing issues with other content +- Move search debug logging to its own log category; add `Searching Minimum Log Level` to `Settings` > `Logging` ## [25.3.1] - 2025-07-24 ### Fixed diff --git a/ErsatzTV.Application/Configuration/Commands/UpdateLoggingSettingsHandler.cs b/ErsatzTV.Application/Configuration/Commands/UpdateLoggingSettingsHandler.cs index a9fe193f4..e9b879511 100644 --- a/ErsatzTV.Application/Configuration/Commands/UpdateLoggingSettingsHandler.cs +++ b/ErsatzTV.Application/Configuration/Commands/UpdateLoggingSettingsHandler.cs @@ -36,6 +36,11 @@ public class UpdateLoggingSettingsHandler : IRequestHandler maybeSchedulingLevel = await _configElementRepository.GetValue(ConfigElementKey.MinimumLogLevelScheduling); + Option maybeSearchingLevel = + await _configElementRepository.GetValue(ConfigElementKey.MinimumLogLevelSearching); + Option maybeStreamingLevel = await _configElementRepository.GetValue(ConfigElementKey.MinimumLogLevelStreaming); @@ -33,6 +36,7 @@ public class GetLoggingSettingsHandler : IRequestHandler new("log.minimum_level"); public static ConfigElementKey MinimumLogLevelScanning => new("log.minimum_level.scanning"); public static ConfigElementKey MinimumLogLevelScheduling => new("log.minimum_level.scheduling"); + public static ConfigElementKey MinimumLogLevelSearching => new("log.minimum_level.searching"); public static ConfigElementKey MinimumLogLevelStreaming => new("log.minimum_level.streaming"); public static ConfigElementKey MinimumLogLevelHttp => new("log.minimum_level.http"); public static ConfigElementKey FFmpegPath => new("ffmpeg.ffmpeg_path"); diff --git a/ErsatzTV.Core/LoggingLevelSwitches.cs b/ErsatzTV.Core/LoggingLevelSwitches.cs index c26960316..ba0b7c84e 100644 --- a/ErsatzTV.Core/LoggingLevelSwitches.cs +++ b/ErsatzTV.Core/LoggingLevelSwitches.cs @@ -10,6 +10,8 @@ public class LoggingLevelSwitches public LoggingLevelSwitch SchedulingLevelSwitch { get; } = new(); + public LoggingLevelSwitch SearchingLevelSwitch { get; } = new(); + public LoggingLevelSwitch StreamingLevelSwitch { get; } = new(); public LoggingLevelSwitch HttpLevelSwitch { get; } = new(); diff --git a/ErsatzTV.Infrastructure/Search/SearchQueryParser.cs b/ErsatzTV.Infrastructure/Search/SearchQueryParser.cs index 3a4fdc3f0..f89415292 100644 --- a/ErsatzTV.Infrastructure/Search/SearchQueryParser.cs +++ b/ErsatzTV.Infrastructure/Search/SearchQueryParser.cs @@ -6,12 +6,12 @@ using Lucene.Net.Analysis.Miscellaneous; using Lucene.Net.Analysis.Standard; using Lucene.Net.QueryParsers.Classic; using Lucene.Net.Search; -using Serilog; +using Microsoft.Extensions.Logging; using Query = Lucene.Net.Search.Query; namespace ErsatzTV.Infrastructure.Search; -public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCache) +public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCache, ILogger logger) { static SearchQueryParser() => BooleanQuery.MaxClauseCount = 1024 * 4; @@ -54,7 +54,7 @@ public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCach if (!string.IsNullOrWhiteSpace(smartCollectionName) && await smartCollectionCache.HasCycle(smartCollectionName)) { - Log.Logger.Error("Smart collection {Name} contains a cycle; will not evaluate", smartCollectionName); + logger.LogError("Smart collection {Name} contains a cycle; will not evaluate", smartCollectionName); } else { @@ -63,7 +63,7 @@ public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCach { if (replaceCount > 100) { - Log.Logger.Warning("smart_collection query is nested too deep; giving up"); + logger.LogWarning("smart_collection query is nested too deep; giving up"); break; } @@ -75,7 +75,7 @@ public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCach if (parsedQuery == replaceResult.Query) { - Log.Logger.Warning( + logger.LogWarning( "Failed to replace smart_collection in query; is the syntax correct? Quotes are required. Giving up..."); break; } @@ -97,7 +97,7 @@ public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCach }; Query result = ParseQuery(parsedQuery, parser); - Log.Logger.Debug("Search query parsed from [{Query}] to [{ParsedQuery}]", query, result.ToString()); + logger.LogDebug("Search query parsed from [{Query}] to [{ParsedQuery}]", query, result.ToString()); return result; } @@ -113,7 +113,7 @@ public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCach string smartCollectionName = match.Groups[1].Value; if (await smartCollectionCache.HasCycle(smartCollectionName)) { - Log.Logger.Error( + logger.LogError( "Smart collection {Name} contains a cycle; will not evaluate", smartCollectionName); return new ReplaceResult(query, true); @@ -130,7 +130,7 @@ public partial class SearchQueryParser(ISmartCollectionCache smartCollectionCach } catch (Exception ex) { - Log.Logger.Warning(ex, "Unexpected exception replacing smart collections in search query"); + logger.LogWarning(ex, "Unexpected exception replacing smart collections in search query"); return new ReplaceResult(query, true); } } diff --git a/ErsatzTV/Pages/Settings/LoggingSettings.razor b/ErsatzTV/Pages/Settings/LoggingSettings.razor index 8d63ea9d6..f7b710e7d 100644 --- a/ErsatzTV/Pages/Settings/LoggingSettings.razor +++ b/ErsatzTV/Pages/Settings/LoggingSettings.razor @@ -47,6 +47,17 @@ Error + +
+ Searching Minimum Log Level +
+ + Debug + Information + Warning + Error + +
Streaming Minimum Log Level diff --git a/ErsatzTV/Program.cs b/ErsatzTV/Program.cs index 9ee149227..e644e0192 100644 --- a/ErsatzTV/Program.cs +++ b/ErsatzTV/Program.cs @@ -74,6 +74,9 @@ public class Program "ErsatzTV.Application.Subtitles.ExtractEmbeddedSubtitlesHandler", LoggingLevelSwitches.SchedulingLevelSwitch) + // searching + .MinimumLevel.Override("ErsatzTV.Infrastructure.Search.SearchQueryParser", LoggingLevelSwitches.SearchingLevelSwitch) + // streaming .MinimumLevel.Override("ErsatzTV.Application.Streaming", LoggingLevelSwitches.StreamingLevelSwitch) .MinimumLevel.Override("ErsatzTV.FFmpeg", LoggingLevelSwitches.StreamingLevelSwitch) @@ -85,6 +88,7 @@ public class Program LoggingLevelSwitches.StreamingLevelSwitch) .MinimumLevel.Override("ErsatzTV.Controllers.IptvController", LoggingLevelSwitches.StreamingLevelSwitch) .MinimumLevel.Override("ErsatzTV.Controllers.InternalController", LoggingLevelSwitches.StreamingLevelSwitch) + .MinimumLevel.Override("ErsatzTV.Controllers.TroubleshootController", LoggingLevelSwitches.StreamingLevelSwitch) // http .MinimumLevel.Override("Serilog.AspNetCore.RequestLoggingMiddleware", LoggingLevelSwitches.HttpLevelSwitch)