Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
style: fix logger analyzer warnings (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Mar 24, 2024
1 parent 8e18232 commit 0a63921
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ dotnet_diagnostic.s2094.severity = None
# Fix this implementation of 'IDisposable' to conform to the dispose pattern.
dotnet_diagnostic.s3881.severity = None

# Logging in a catch clause should pass the caught exception as a parameter.
dotnet_diagnostic.s6667.severity = error

# Logging arguments should be passed to the correct parameter.
dotnet_diagnostic.s6668.severity = error

# Update this logger to use its enclosing type.
dotnet_diagnostic.s6672.severity = error


## StyleCop.Analyzers

Expand Down
6 changes: 4 additions & 2 deletions Jellyfin.Plugin.Themerr.Tests/TestThemerrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public TestThemerrController(ITestOutputHelper output)
TestLogger.Initialize(output);

Mock<ILibraryManager> mockLibraryManager = new();
Mock<ILogger<ThemerrManager>> mockLogger = new();
Mock<ILogger<ThemerrController>> mockLogger = new();
Mock<IServerConfigurationManager> mockServerConfigurationManager = new();
Mock<ILoggerFactory> mockLoggerFactory = new();

// Create a TestableServerConfiguration with UICulture set to "en-US"
var testableServerConfiguration = new TestableServerConfiguration("en-US");
Expand All @@ -37,7 +38,8 @@ public TestThemerrController(ITestOutputHelper output)
_controller = new ThemerrController(
mockLibraryManager.Object,
mockLogger.Object,
mockServerConfigurationManager.Object);
mockServerConfigurationManager.Object,
mockLoggerFactory.Object);
}

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions Jellyfin.Plugin.Themerr/Api/ThemerrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Jellyfin.Plugin.Themerr.Api
public class ThemerrController : ControllerBase
{
private readonly ThemerrManager _themerrManager;
private readonly ILogger<ThemerrManager> _logger;
private readonly ILogger<ThemerrController> _logger;
private readonly IServerConfigurationManager _configurationManager;

/// <summary>
Expand All @@ -36,12 +36,14 @@ public class ThemerrController : ControllerBase
/// <param name="libraryManager">The library manager.</param>
/// <param name="logger">The logger.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="loggerFactory">The logger factory.</param>
public ThemerrController(
ILibraryManager libraryManager,
ILogger<ThemerrManager> logger,
IServerConfigurationManager configurationManager)
ILogger<ThemerrController> logger,
IServerConfigurationManager configurationManager,
ILoggerFactory loggerFactory)
{
_themerrManager = new ThemerrManager(libraryManager, logger);
_themerrManager = new ThemerrManager(libraryManager, loggerFactory.CreateLogger<ThemerrManager>());
_logger = logger;
_configurationManager = configurationManager;
}
Expand Down
10 changes: 7 additions & 3 deletions Jellyfin.Plugin.Themerr/ScheduledTasks/ThemerrTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ namespace Jellyfin.Plugin.Themerr.ScheduledTasks
/// </summary>
public class ThemerrTasks : IScheduledTask
{
private readonly ILogger<ThemerrManager> _logger;
private readonly ILogger<ThemerrTasks> _logger;
private readonly ThemerrManager _themerrManager;

/// <summary>
/// Initializes a new instance of the <see cref="ThemerrTasks"/> class.
/// </summary>
/// <param name="libraryManager">The library manager.</param>
/// <param name="logger">The logger.</param>
public ThemerrTasks(ILibraryManager libraryManager, ILogger<ThemerrManager> logger)
/// <param name="loggerFactory">The logger factory.</param>
public ThemerrTasks(
ILibraryManager libraryManager,
ILogger<ThemerrTasks> logger,
ILoggerFactory loggerFactory)
{
_logger = logger;
_themerrManager = new ThemerrManager(libraryManager, logger);
_themerrManager = new ThemerrManager(libraryManager, loggerFactory.CreateLogger<ThemerrManager>());
}

/// <summary>
Expand Down
11 changes: 4 additions & 7 deletions Jellyfin.Plugin.Themerr/ThemerrManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public bool SaveMp3(string destination, string videoUrl)
}
catch (Exception e)
{
_logger.LogError("Unable to download {VideoUrl} to {Destination}: {Error}", videoUrl, destination, e);
_logger.LogError(e, "Unable to download {VideoUrl} to {Destination}", videoUrl, destination);
return false;
}

Expand Down Expand Up @@ -331,12 +331,9 @@ public string GetYoutubeThemeUrl(string themerrDbUrl, BaseItem item)
dynamic jsonData = JsonConvert.DeserializeObject(jsonString);
return jsonData?.youtube_theme_url;
}
catch (Exception)
catch (Exception e)
{
_logger.LogWarning(
"Missing from ThemerrDB: {ItemTitle}, contribute:\n {IssueUrl}",
item.Name,
GetIssueUrl(item));
_logger.LogWarning(e, "Missing from ThemerrDB: {ItemTitle}, contribute:\n {IssueUrl}", item.Name, GetIssueUrl(item));
return string.Empty;
}
}
Expand Down Expand Up @@ -405,7 +402,7 @@ public bool SaveThemerrData(string themePath, string themerrDataPath, string you
}
catch (Exception e)
{
_logger.LogError("Unable to save themerr data to {ThemerrDataPath}: {Error}", themerrDataPath, e);
_logger.LogError(e, "Unable to save themerr data to {ThemerrDataPath}", themerrDataPath);
}

return success && WaitForFile(themerrDataPath, 10000);
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
],
'Extensions.Logging': [
'ILogger',
'ILoggerFactory',
],
},
'Jellyfin.Controller.MediaBrowser.Common.Configuration': {
Expand Down

0 comments on commit 0a63921

Please sign in to comment.