Remove ClientLog endpoints
This commit is contained in:
parent
17a273d237
commit
ea355b4262
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System.Net.Mime;
|
||||||
using System.Net.Mime;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Api.Attributes;
|
using Jellyfin.Api.Attributes;
|
||||||
using Jellyfin.Api.Constants;
|
using Jellyfin.Api.Constants;
|
||||||
|
@ -7,7 +6,6 @@ using Jellyfin.Api.Helpers;
|
||||||
using Jellyfin.Api.Models.ClientLogDtos;
|
using Jellyfin.Api.Models.ClientLogDtos;
|
||||||
using MediaBrowser.Controller.ClientEvent;
|
using MediaBrowser.Controller.ClientEvent;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Model.ClientLog;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -37,54 +35,6 @@ namespace Jellyfin.Api.Controllers
|
||||||
_serverConfigurationManager = serverConfigurationManager;
|
_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>
|
/// <summary>
|
||||||
/// Upload a document.
|
/// Upload a document.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -111,39 +61,20 @@ namespace Jellyfin.Api.Controllers
|
||||||
return StatusCode(StatusCodes.Status413PayloadTooLarge, $"Payload must be less than {MaxDocumentSize:N0} bytes");
|
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)
|
var fileName = await _clientEventLogger.WriteDocumentAsync(clientName, clientVersion, Request.Body)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok(new ClientLogDocumentResponseDto(fileName));
|
return Ok(new ClientLogDocumentResponseDto(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Log(
|
private (string ClientName, string ClientVersion) GetRequestInformation()
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
var clientName = ClaimHelpers.GetClient(HttpContext.User) ?? "unknown-client";
|
var clientName = ClaimHelpers.GetClient(HttpContext.User) ?? "unknown-client";
|
||||||
var clientVersion = ClaimHelpers.GetIsApiKey(HttpContext.User)
|
var clientVersion = ClaimHelpers.GetIsApiKey(HttpContext.User)
|
||||||
? "apikey"
|
? "apikey"
|
||||||
: ClaimHelpers.GetVersion(HttpContext.User) ?? "unknown-version";
|
: 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.Console" Version="4.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.Graylog" Version="2.2.2" />
|
<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" />
|
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.0.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ using Emby.Server.Implementations;
|
||||||
using Jellyfin.Server.Implementations;
|
using Jellyfin.Server.Implementations;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller.ClientEvent;
|
|
||||||
using MediaBrowser.Controller.Extensions;
|
using MediaBrowser.Controller.Extensions;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
@ -26,7 +25,6 @@ using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using Serilog.Extensions.Logging;
|
using Serilog.Extensions.Logging;
|
||||||
using Serilog.Filters;
|
|
||||||
using SQLitePCL;
|
using SQLitePCL;
|
||||||
using ConfigurationExtensions = MediaBrowser.Controller.Extensions.ConfigurationExtensions;
|
using ConfigurationExtensions = MediaBrowser.Controller.Extensions.ConfigurationExtensions;
|
||||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||||
|
@ -598,46 +596,22 @@ namespace Jellyfin.Server
|
||||||
{
|
{
|
||||||
// Serilog.Log is used by SerilogLoggerFactory when no logger is specified
|
// Serilog.Log is used by SerilogLoggerFactory when no logger is specified
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.WriteTo.Logger(lc =>
|
.ReadFrom.Configuration(configuration)
|
||||||
lc.ReadFrom.Configuration(configuration)
|
.Enrich.FromLogContext()
|
||||||
.Enrich.FromLogContext()
|
.Enrich.WithThreadId()
|
||||||
.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>()))
|
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.WriteTo.Logger(lc =>
|
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}")
|
||||||
lc.WriteTo.Async(x => x.File(
|
.WriteTo.Async(x => x.File(
|
||||||
Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
|
Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
|
||||||
rollingInterval: RollingInterval.Day,
|
rollingInterval: RollingInterval.Day,
|
||||||
outputTemplate: "{Message:l}{NewLine}{Exception}",
|
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message}{NewLine}{Exception}",
|
||||||
encoding: Encoding.UTF8))
|
encoding: Encoding.UTF8))
|
||||||
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] [{ThreadId}] {SourceContext}: {Message:lj}{NewLine}{Exception}")
|
.Enrich.FromLogContext()
|
||||||
.Enrich.FromLogContext()
|
.Enrich.WithThreadId()
|
||||||
.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>()))
|
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
|
|
||||||
Log.Logger.Fatal(ex, "Failed to create/read logger configuration");
|
Log.Logger.Fatal(ex, "Failed to create/read logger configuration");
|
||||||
|
|
|
@ -1,47 +1,23 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Model.ClientLog;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.ClientEvent
|
namespace MediaBrowser.Controller.ClientEvent
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public class ClientEventLogger : IClientEventLogger
|
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;
|
private readonly IServerApplicationPaths _applicationPaths;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
|
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Instance of the <see cref="ILogger{ClientEventLogger}"/> interface.</param>
|
|
||||||
/// <param name="applicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param>
|
/// <param name="applicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param>
|
||||||
public ClientEventLogger(
|
public ClientEventLogger(IServerApplicationPaths applicationPaths)
|
||||||
ILogger<ClientEventLogger> logger,
|
|
||||||
IServerApplicationPaths applicationPaths)
|
|
||||||
{
|
{
|
||||||
_logger = logger;
|
|
||||||
_applicationPaths = applicationPaths;
|
_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 />
|
/// <inheritdoc />
|
||||||
public async Task<string> WriteDocumentAsync(string clientName, string clientVersion, Stream fileContents)
|
public async Task<string> WriteDocumentAsync(string clientName, string clientVersion, Stream fileContents)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Model.ClientLog;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.ClientEvent
|
namespace MediaBrowser.Controller.ClientEvent
|
||||||
{
|
{
|
||||||
|
@ -10,12 +8,6 @@ namespace MediaBrowser.Controller.ClientEvent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IClientEventLogger
|
public interface IClientEventLogger
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Logs the event from the client.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="clientLogEvent">The client log event.</param>
|
|
||||||
void Log(ClientLogEvent clientLogEvent);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes a file to the log directory.
|
/// Writes a file to the log directory.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user