From 7642fe046b242c9399cdf93a06266677739680ca Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 27 Apr 2019 16:54:33 -0700 Subject: [PATCH] New: Log when release is matched by ID instead of title Closes #446 --- .../Extensions/SentryLoggerExtensions.cs | 5 +-- src/NzbDrone.Core/Parser/ParsingService.cs | 32 ++++++++++++++++--- src/NzbDrone.Test.Common/LoggingTest.cs | 9 ++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs b/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs index 3084d380b..2e17aad44 100644 --- a/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs +++ b/src/NzbDrone.Common/Instrumentation/Extensions/SentryLoggerExtensions.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; using NLog; using NLog.Fluent; diff --git a/src/NzbDrone.Core/Parser/ParsingService.cs b/src/NzbDrone.Core/Parser/ParsingService.cs index 096d84955..09e0ee6cf 100644 --- a/src/NzbDrone.Core/Parser/ParsingService.cs +++ b/src/NzbDrone.Core/Parser/ParsingService.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NLog.Fluent; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Parser.Model; @@ -243,13 +245,21 @@ namespace NzbDrone.Core.Parser if (tvdbId > 0 && tvdbId == searchCriteria.Series.TvdbId) { - //TODO: If series is found by TvdbId, we should report it as a scene naming exception, since it will fail to import + _logger.Debug() + .Message("Found matching series by TVDB ID (0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle) + .WriteSentryWarn("TvdbIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle) + .Write(); + return searchCriteria.Series; } if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId) { - //TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import + _logger.Debug() + .Message("Found matching series by TVRage ID (0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle) + .WriteSentryWarn("TvRageIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle) + .Write(); + return searchCriteria.Series; } } @@ -263,14 +273,28 @@ namespace NzbDrone.Core.Parser if (series == null && tvdbId > 0) { - //TODO: If series is found by TvdbId, we should report it as a scene naming exception, since it will fail to import series = _seriesService.FindByTvdbId(tvdbId); + + if (series != null) + { + _logger.Debug() + .Message("Found matching series by TVDB ID (0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle) + .WriteSentryWarn("TvdbIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle) + .Write(); + } } if (series == null && tvRageId > 0) { - //TODO: If series is found by TvRageId, we should report it as a scene naming exception, since it will fail to import series = _seriesService.FindByTvRageId(tvRageId); + + if (series != null) + { + _logger.Debug() + .Message("Found matching series by TVRage ID (0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle) + .WriteSentryWarn("TvRageIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle) + .Write(); + } } if (series == null) diff --git a/src/NzbDrone.Test.Common/LoggingTest.cs b/src/NzbDrone.Test.Common/LoggingTest.cs index 7765aff1b..1a1f9e3ff 100644 --- a/src/NzbDrone.Test.Common/LoggingTest.cs +++ b/src/NzbDrone.Test.Common/LoggingTest.cs @@ -26,6 +26,8 @@ namespace NzbDrone.Test.Common var logOutput = TestLogOutput.Console; Enum.TryParse(Environment.GetEnvironmentVariable("SONARR_TESTS_LOG_OUTPUT"), out logOutput); + RegisterSentryLogger(); + switch (logOutput) { case TestLogOutput.Console: @@ -68,6 +70,13 @@ namespace NzbDrone.Test.Common LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, fileTarget)); } + private static void RegisterSentryLogger() + { + // Register a null target for sentry logs, so they aren't caught by other loggers. + var loggingRuleSentry = new LoggingRule("Sentry", LogLevel.Debug, new NullTarget()) { Final = true }; + LogManager.Configuration.LoggingRules.Insert(0, loggingRuleSentry); + } + private static void RegisterExceptionVerification() { var exceptionVerification = new ExceptionVerification();