Significantly refactored code to help with readability of logging and episode processing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Jellyfin.Plugin.MediaCleaner.Configuration;
|
||||
using Jellyfin.Plugin.MediaCleaner.Models;
|
||||
@@ -10,150 +11,25 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.MediaCleaner.Helpers;
|
||||
|
||||
public class LoggingHelper
|
||||
public class LoggingHelper(ILogger logger)
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger _logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
public LoggingHelper(ILogger logger)
|
||||
[SuppressMessage("Microsoft.Performance", "CA2254:TemplateShouldBeConstant", Justification = "Message parameter is intentionally variable for flexible debug logging")]
|
||||
public void LogDebugInformation(string message, params object?[] args)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation(message, args);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Performance", "CA2254:TemplateShouldBeConstant", Justification = "Message parameter is intentionally variable for flexible logging")]
|
||||
public void LogInformation(string message, params object?[] args)
|
||||
{
|
||||
_logger.LogInformation(message, args);
|
||||
}
|
||||
|
||||
private static PluginConfiguration Configuration =>
|
||||
Plugin.Instance!.Configuration;
|
||||
|
||||
public void StartLogging()
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("--DEBUG MODE ACTIVE--");
|
||||
}
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Starting stale media scan...");
|
||||
}
|
||||
|
||||
public void EndLogging()
|
||||
{
|
||||
_logger.LogInformation("Ending stale media scan...");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void PrintDebugEndOfScanningForSeries(BaseItem item)
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("End of scanning for series: {Series}", item);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void StartScanningSeriesItems()
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Starting scan of series items.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void StartScanningMoviesItems()
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Starting scan of movies items.");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void PrintItemsInformation(IReadOnlyCollection<BaseItem> items)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(items);
|
||||
|
||||
_logger.LogInformation("Total items: {ItemCount}", items.Count);
|
||||
_logger.LogInformation("Stale items found: {AllItems}", items);
|
||||
}
|
||||
|
||||
public void PrintStaleMoviesInformation(IReadOnlyCollection<BaseItem> staleMovies)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(staleMovies);
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
|
||||
|
||||
if (staleMovies.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
foreach (var movieInfo in staleMovies)
|
||||
{
|
||||
_logger.LogInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintStaleEpisodesInformation(Func<IReadOnlyCollection<BaseItem>, List<SeriesInfo>> findSeriesInfoFromEpisodes, IReadOnlyCollection<BaseItem> staleEpisodes)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(staleEpisodes);
|
||||
ArgumentNullException.ThrowIfNull(findSeriesInfoFromEpisodes);
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Stale Episodes found: {StaleEpisodes}", staleEpisodes.Count);
|
||||
|
||||
if (staleEpisodes.Count > 0 && Configuration.DebugMode)
|
||||
{
|
||||
if (findSeriesInfoFromEpisodes == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(findSeriesInfoFromEpisodes), "The method to find series information cannot be null.");
|
||||
}
|
||||
|
||||
List<SeriesInfo> seriesInfoList = findSeriesInfoFromEpisodes(staleEpisodes);
|
||||
|
||||
foreach (var seriesInfo in seriesInfoList)
|
||||
{
|
||||
_logger.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
|
||||
public void PrintDebugDataForSeries(BaseItem item)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(item);
|
||||
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Debug data for series: {SeriesName}", item.Name);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugSeasonInfo()
|
||||
{
|
||||
if (Configuration.DebugMode)
|
||||
{
|
||||
_logger.LogInformation("Season debug information:");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugEpisodesWithUserData(IReadOnlyCollection<BaseItem> episodesWithUserData)
|
||||
{
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("Episodes with user data: {EpisodesWithUserData}", episodesWithUserData);
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
public void PrintDebugEpisodeCreationInfo(IReadOnlyCollection<BaseItem> episodes)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(episodes);
|
||||
|
||||
if(Configuration.DebugMode){
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
_logger.LogInformation("Episode creation dates:");
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
foreach(BaseItem episode in episodes)
|
||||
{
|
||||
_logger.LogInformation("Episode: {EpisodeName} | Date Created: {EpisodeDateCreated}", [episode.Name, episode.DateCreated]);
|
||||
}
|
||||
_logger.LogInformation("-------------------------------------------------");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user