aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaus Vium <cvium@users.noreply.github.com>2021-11-21 23:57:13 +0100
committerGitHub <noreply@github.com>2021-11-21 23:57:13 +0100
commit39e6658d01e10609c460fb92a7af583e4d04caab (patch)
tree18f12cc9d039dc21c7d4cf95a39cfe81eb724d0b
parent8f051c86f7d1f02c9a0d917cf0d0ed52aa88ce6b (diff)
parentea355b4262fa0b817930d2bb751c05e6e0ee3022 (diff)
Merge pull request #6879 from crobibero/client-log-cleanup
Remove ClientLog endpoints
-rw-r--r--Jellyfin.Api/Controllers/ClientLogController.cs77
-rw-r--r--Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs30
-rw-r--r--Jellyfin.Server/Jellyfin.Server.csproj1
-rw-r--r--Jellyfin.Server/Program.cs48
-rw-r--r--MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs26
-rw-r--r--MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs8
6 files changed, 16 insertions, 174 deletions
diff --git a/Jellyfin.Api/Controllers/ClientLogController.cs b/Jellyfin.Api/Controllers/ClientLogController.cs
index 95d07c930..98fd22430 100644
--- a/Jellyfin.Api/Controllers/ClientLogController.cs
+++ b/Jellyfin.Api/Controllers/ClientLogController.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Net.Mime;
+using System.Net.Mime;
using System.Threading.Tasks;
using Jellyfin.Api.Attributes;
using Jellyfin.Api.Constants;
@@ -7,7 +6,6 @@ using Jellyfin.Api.Helpers;
using Jellyfin.Api.Models.ClientLogDtos;
using MediaBrowser.Controller.ClientEvent;
using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Model.ClientLog;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -38,54 +36,6 @@ namespace Jellyfin.Api.Controllers
}
/// <summary>
- /// Post event from client.
- /// </summary>
- /// <param name="clientLogEventDto">The client log dto.</param>
- /// <response code="204">Event logged.</response>
- /// <response code="403">Event logging disabled.</response>
- /// <returns>Submission status.</returns>
- [HttpPost]
- [ProducesResponseType(StatusCodes.Status204NoContent)]
- [ProducesResponseType(StatusCodes.Status403Forbidden)]
- public ActionResult LogEvent([FromBody] ClientLogEventDto clientLogEventDto)
- {
- if (!_serverConfigurationManager.Configuration.AllowClientLogUpload)
- {
- return Forbid();
- }
-
- var (clientName, clientVersion, userId, deviceId) = GetRequestInformation();
- Log(clientLogEventDto, userId, clientName, clientVersion, deviceId);
- return NoContent();
- }
-
- /// <summary>
- /// Bulk post events from client.
- /// </summary>
- /// <param name="clientLogEventDtos">The list of client log dtos.</param>
- /// <response code="204">All events logged.</response>
- /// <response code="403">Event logging disabled.</response>
- /// <returns>Submission status.</returns>
- [HttpPost("Bulk")]
- [ProducesResponseType(StatusCodes.Status204NoContent)]
- [ProducesResponseType(StatusCodes.Status403Forbidden)]
- public ActionResult LogEvents([FromBody] ClientLogEventDto[] clientLogEventDtos)
- {
- if (!_serverConfigurationManager.Configuration.AllowClientLogUpload)
- {
- return Forbid();
- }
-
- var (clientName, clientVersion, userId, deviceId) = GetRequestInformation();
- foreach (var dto in clientLogEventDtos)
- {
- Log(dto, userId, clientName, clientVersion, deviceId);
- }
-
- return NoContent();
- }
-
- /// <summary>
/// Upload a document.
/// </summary>
/// <response code="200">Document saved.</response>
@@ -111,39 +61,20 @@ namespace Jellyfin.Api.Controllers
return StatusCode(StatusCodes.Status413PayloadTooLarge, $"Payload must be less than {MaxDocumentSize:N0} bytes");
}
- var (clientName, clientVersion, _, _) = GetRequestInformation();
+ var (clientName, clientVersion) = GetRequestInformation();
var fileName = await _clientEventLogger.WriteDocumentAsync(clientName, clientVersion, Request.Body)
.ConfigureAwait(false);
return Ok(new ClientLogDocumentResponseDto(fileName));
}
- private void Log(
- ClientLogEventDto dto,
- Guid userId,
- string clientName,
- string clientVersion,
- string deviceId)
- {
- _clientEventLogger.Log(new ClientLogEvent(
- dto.Timestamp,
- dto.Level,
- userId,
- clientName,
- clientVersion,
- deviceId,
- dto.Message));
- }
-
- private (string ClientName, string ClientVersion, Guid UserId, string DeviceId) GetRequestInformation()
+ private (string ClientName, string ClientVersion) GetRequestInformation()
{
var clientName = ClaimHelpers.GetClient(HttpContext.User) ?? "unknown-client";
var clientVersion = ClaimHelpers.GetIsApiKey(HttpContext.User)
? "apikey"
: ClaimHelpers.GetVersion(HttpContext.User) ?? "unknown-version";
- var userId = ClaimHelpers.GetUserId(HttpContext.User) ?? Guid.Empty;
- var deviceId = ClaimHelpers.GetDeviceId(HttpContext.User) ?? "unknown-device-id";
- return (clientName, clientVersion, userId, deviceId);
+ return (clientName, clientVersion);
}
}
}
diff --git a/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs b/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs
deleted file mode 100644
index 9bf9be0a4..000000000
--- a/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using System.ComponentModel.DataAnnotations;
-using Microsoft.Extensions.Logging;
-
-namespace Jellyfin.Api.Models.ClientLogDtos
-{
- /// <summary>
- /// The client log dto.
- /// </summary>
- public class ClientLogEventDto
- {
- /// <summary>
- /// Gets or sets the event timestamp.
- /// </summary>
- [Required]
- public DateTime Timestamp { get; set; }
-
- /// <summary>
- /// Gets or sets the log level.
- /// </summary>
- [Required]
- public LogLevel Level { get; set; }
-
- /// <summary>
- /// Gets or sets the log message.
- /// </summary>
- [Required]
- public string Message { get; set; } = string.Empty;
- }
-}
diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj
index 045ed6a2b..30b6bff9f 100644
--- a/Jellyfin.Server/Jellyfin.Server.csproj
+++ b/Jellyfin.Server/Jellyfin.Server.csproj
@@ -44,7 +44,6 @@
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Graylog" Version="2.2.2" />
- <PackageReference Include="Serilog.Sinks.Map" Version="1.0.2" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" />
</ItemGroup>
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index 6e4c2280b..7f158aebb 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -13,7 +13,6 @@ using Emby.Server.Implementations;
using Jellyfin.Server.Implementations;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.ClientEvent;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Model.IO;
using Microsoft.AspNetCore.Hosting;
@@ -26,7 +25,6 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Serilog;
using Serilog.Extensions.Logging;
-using Serilog.Filters;
using SQLitePCL;
using ConfigurationExtensions = MediaBrowser.Controller.Extensions.ConfigurationExtensions;
using ILogger = Microsoft.Extensions.Logging.ILogger;
@@ -598,46 +596,22 @@ namespace Jellyfin.Server
{
// Serilog.Log is used by SerilogLoggerFactory when no logger is specified
Log.Logger = new LoggerConfiguration()
- .WriteTo.Logger(lc =>
- lc.ReadFrom.Configuration(configuration)
- .Enrich.FromLogContext()
- .Enrich.WithThreadId()
- .Filter.ByExcluding(Matching.FromSource<ClientEventLogger>()))
- .WriteTo.Logger(lc =>
- lc.WriteTo.Map(
- "ClientName",
- (clientName, wt)
- => wt.File(
- Path.Combine(appPaths.LogDirectoryPath, "log_" + clientName + "_.log"),
- rollingInterval: RollingInterval.Day,
- outputTemplate: "{Message:l}{NewLine}{Exception}",
- encoding: Encoding.UTF8))
- .Filter.ByIncludingOnly(Matching.FromSource<ClientEventLogger>()))
+ .ReadFrom.Configuration(configuration)
+ .Enrich.FromLogContext()
+ .Enrich.WithThreadId()
.CreateLogger();
}
catch (Exception ex)
{
Log.Logger = new LoggerConfiguration()
- .WriteTo.Logger(lc =>
- lc.WriteTo.Async(x => x.File(
- Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
- rollingInterval: RollingInterval.Day,
- outputTemplate: "{Message:l}{NewLine}{Exception}",
- encoding: Encoding.UTF8))
- .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}")
- .Enrich.FromLogContext()
- .Enrich.WithThreadId())
- .WriteTo.Logger(lc =>
- lc
- .WriteTo.Map(
- "ClientName",
- (clientName, wt)
- => wt.File(
- Path.Combine(appPaths.LogDirectoryPath, "log_" + clientName + "_.log"),
- rollingInterval: RollingInterval.Day,
- outputTemplate: "{Message:l}{NewLine}{Exception}",
- encoding: Encoding.UTF8))
- .Filter.ByIncludingOnly(Matching.FromSource<ClientEventLogger>()))
+ .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}")
+ .WriteTo.Async(x => x.File(
+ Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
+ rollingInterval: RollingInterval.Day,
+ outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message}{NewLine}{Exception}",
+ encoding: Encoding.UTF8))
+ .Enrich.FromLogContext()
+ .Enrich.WithThreadId()
.CreateLogger();
Log.Logger.Fatal(ex, "Failed to create/read logger configuration");
diff --git a/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs b/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs
index 82b5b4593..dea1c2f32 100644
--- a/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs
+++ b/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs
@@ -1,48 +1,24 @@
using System;
using System.IO;
using System.Threading.Tasks;
-using MediaBrowser.Model.ClientLog;
-using Microsoft.Extensions.Logging;
namespace MediaBrowser.Controller.ClientEvent
{
/// <inheritdoc />
public class ClientEventLogger : IClientEventLogger
{
- private const string LogString = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level}] [{ClientName}:{ClientVersion}]: UserId: {UserId} DeviceId: {DeviceId}{NewLine}{Message}";
- private readonly ILogger<ClientEventLogger> _logger;
private readonly IServerApplicationPaths _applicationPaths;
/// <summary>
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
/// </summary>
- /// <param name="logger">Instance of the <see cref="ILogger{ClientEventLogger}"/> interface.</param>
/// <param name="applicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param>
- public ClientEventLogger(
- ILogger<ClientEventLogger> logger,
- IServerApplicationPaths applicationPaths)
+ public ClientEventLogger(IServerApplicationPaths applicationPaths)
{
- _logger = logger;
_applicationPaths = applicationPaths;
}
/// <inheritdoc />
- public void Log(ClientLogEvent clientLogEvent)
- {
- _logger.Log(
- LogLevel.Critical,
- LogString,
- clientLogEvent.Timestamp,
- clientLogEvent.Level.ToString(),
- clientLogEvent.ClientName,
- clientLogEvent.ClientVersion,
- clientLogEvent.UserId ?? Guid.Empty,
- clientLogEvent.DeviceId,
- Environment.NewLine,
- clientLogEvent.Message);
- }
-
- /// <inheritdoc />
public async Task<string> WriteDocumentAsync(string clientName, string clientVersion, Stream fileContents)
{
var fileName = $"upload_{clientName}_{clientVersion}_{DateTime.UtcNow:yyyyMMddHHmmss}_{Guid.NewGuid():N}.log";
diff --git a/MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs b/MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs
index 34968d493..ad8a1bd24 100644
--- a/MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs
+++ b/MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs
@@ -1,7 +1,5 @@
using System.IO;
using System.Threading.Tasks;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.ClientLog;
namespace MediaBrowser.Controller.ClientEvent
{
@@ -11,12 +9,6 @@ namespace MediaBrowser.Controller.ClientEvent
public interface IClientEventLogger
{
/// <summary>
- /// Logs the event from the client.
- /// </summary>
- /// <param name="clientLogEvent">The client log event.</param>
- void Log(ClientLogEvent clientLogEvent);
-
- /// <summary>
/// Writes a file to the log directory.
/// </summary>
/// <param name="clientName">The client name writing the document.</param>