From cfc11b904af08b04a711a19cc98cb3ce2dfe366b Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 13 Aug 2024 17:16:55 +0200 Subject: [PATCH] Added DTO for emitting log data. This fixes #5435 --- Duplicati/WebserverCore/Dto/LogEntry.cs | 82 +++++++++++++++++++ .../WebserverCore/Endpoints/V1/LogData.cs | 4 +- 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 Duplicati/WebserverCore/Dto/LogEntry.cs diff --git a/Duplicati/WebserverCore/Dto/LogEntry.cs b/Duplicati/WebserverCore/Dto/LogEntry.cs new file mode 100644 index 000000000..cdadc71d3 --- /dev/null +++ b/Duplicati/WebserverCore/Dto/LogEntry.cs @@ -0,0 +1,82 @@ +using Duplicati.Library.Logging; +using Duplicati.Server; + +namespace Duplicati.WebserverCore.Dto; + +/// +/// DTO entry for reporting a log entry +/// +public sealed record LogEntry +{ + /// + /// The time the message was logged + /// + public required DateTime When { get; init; } + + /// + /// The ID assigned to the message + /// + public required long ID { get; init; } + + /// + /// The logged message + /// + public required string Message { get; init; } + + /// + /// The log tag + /// + public required string Tag { get; init; } + + /// + /// The message ID + /// + public required string MessageID { get; init; } + + /// + /// The message ID + /// + public required string ExceptionID { get; init; } + + /// + /// The message type + /// + public required LogMessageType Type { get; init; } + + /// + /// Exception data attached to the message + /// + public required Exception Exception { get; init; } + + /// + /// The backup ID, if any + /// + public required string BackupID { get; init; } + + /// + /// The task ID, if any + /// + public required string TaskID { get; init; } + + /// + /// Convert the internal record to a DTO record + /// + /// The internal record + /// The DTO record + public static LogEntry FromInternalEntry(LogWriteHandler.LogEntry entry) + { + return new LogEntry + { + When = entry.When, + ID = entry.ID, + Message = entry.Message, + Tag = entry.Tag, + MessageID = entry.MessageID, + ExceptionID = entry.ExceptionID, + Type = entry.Type, + Exception = entry.Exception, + BackupID = entry.BackupID, + TaskID = entry.TaskID + }; + } +} diff --git a/Duplicati/WebserverCore/Endpoints/V1/LogData.cs b/Duplicati/WebserverCore/Endpoints/V1/LogData.cs index 46363e20e..e6d457eb6 100644 --- a/Duplicati/WebserverCore/Endpoints/V1/LogData.cs +++ b/Duplicati/WebserverCore/Endpoints/V1/LogData.cs @@ -18,10 +18,10 @@ public class LogData : IEndpointV1 .RequireAuthorization(); } - private static Server.LogWriteHandler.LogEntry[] ExecuteLogPoll(Library.Logging.LogMessageType level, long id, long offset, int pagesize) + private static Dto.LogEntry[] ExecuteLogPoll(Library.Logging.LogMessageType level, long id, long offset, int pagesize) { pagesize = Math.Max(1, Math.Min(500, pagesize)); - return FIXMEGlobal.LogHandler.AfterID(id, level, pagesize); + return FIXMEGlobal.LogHandler.AfterID(id, level, pagesize).Select(x => Dto.LogEntry.FromInternalEntry(x)).ToArray(); } private static List>? ExecuteGetLog(Connection connection, long? offset, long pagesize)