Skip to content

Commit

Permalink
More logs
Browse files Browse the repository at this point in the history
  • Loading branch information
shemanaev committed Jan 28, 2024
1 parent 20e3b44 commit 163cedb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Jellyfin.Webhooks/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ IHttpClientFactory httpClientFactory

_scrobbled = new List<Guid>();
_deviceStates = new Dictionary<string, DeviceState>();
_formatFactory = new FormatFactory(httpClientFactory, dtoService, _userManager);
_formatFactory = new FormatFactory(httpClientFactory, dtoService, _userManager, logger);
}

public void Dispose()
Expand Down Expand Up @@ -364,7 +364,7 @@ private async Task ExecuteWebhook(EventInfo request)
var formatter = _formatFactory.CreateFormat(hook.Format);
try
{
_logger.LogInformation("ExecuteWebhook: {id}", hook.Id);
_logger.LogInformation("ExecuteWebhook: {id}, format: {format}, url: {url}", hook.Id, hook.Format, hook.Url);
await formatter.Format(new Uri(hook.Url), request);
}
catch (Exception e)
Expand Down
12 changes: 9 additions & 3 deletions Jellyfin.Webhooks/Formats/DefaultFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Dto;
using MediaBrowser.Controller.Entities.TV;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Webhooks.Formats
{
Expand All @@ -18,12 +19,14 @@ internal class DefaultFormat : IFormat
private readonly HttpClient _http;
private readonly IDtoService _dto;
private readonly IUserManager _users;
private readonly ILogger _logger;

public DefaultFormat(HttpClient http, IDtoService dto, IUserManager users)
public DefaultFormat(HttpClient http, IDtoService dto, IUserManager users, ILogger logger)
{
_http = http;
_dto = dto;
_users = users;
_logger = logger;
}

public async Task Format(Uri url, EventInfo info)
Expand All @@ -42,8 +45,11 @@ public async Task Format(Uri url, EventInfo info)
Series = series,
};

var content = new StringContent(JsonSerializer.Serialize(body, JsonDefaults.Options), Encoding.UTF8, "application/json");
await _http.PostAsync(url, content);
var contentJson = JsonSerializer.Serialize(body, JsonDefaults.Options);
var content = new StringContent(contentJson, Encoding.UTF8, "application/json");
_logger.LogInformation("Calling url: {url} (size: {size})", url, contentJson.Length);
var response = await _http.PostAsync(url, content);
_logger.LogInformation($"Response: {response}");
}
}

Expand Down
7 changes: 5 additions & 2 deletions Jellyfin.Webhooks/Formats/FormatFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Webhooks.Formats
{
Expand All @@ -11,19 +12,21 @@ internal class FormatFactory
private readonly IHttpClientFactory _httpClientFactory;
private readonly IDtoService _dto;
private readonly IUserManager _users;
private readonly ILoggerFactory _loggerFactory;

public FormatFactory(IHttpClientFactory http, IDtoService dto, IUserManager users)
public FormatFactory(IHttpClientFactory http, IDtoService dto, IUserManager users, ILoggerFactory logger)
{
_httpClientFactory = http;
_dto = dto;
_users = users;
_loggerFactory = logger;
}

public IFormat CreateFormat(HookFormat format) => format switch
{
HookFormat.Get => new GetFormat(GetHttpClient()),
HookFormat.Plex => new PlexFormat(),
_ => new DefaultFormat(GetHttpClient(), _dto, _users),
_ => new DefaultFormat(GetHttpClient(), _dto, _users, _loggerFactory.CreateLogger("Webhooks.DefaultFormat")),
};

private HttpClient GetHttpClient()
Expand Down

0 comments on commit 163cedb

Please sign in to comment.