Merge pull request #6879 from crobibero/client-log-cleanup
Remove ClientLog endpoints
This commit is contained in:
commit
39e6658d01
|
@ -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;
|
||||
|
@ -37,54 +35,6 @@ namespace Jellyfin.Api.Controllers
|
|||
_serverConfigurationManager = serverConfigurationManager;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -1,47 +1,23 @@
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.ClientLog;
|
||||
|
||||
namespace MediaBrowser.Controller.ClientEvent
|
||||
{
|
||||
|
@ -10,12 +8,6 @@ namespace MediaBrowser.Controller.ClientEvent
|
|||
/// </summary>
|
||||
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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user