Added DTO for emitting log data.

This fixes #5435
This commit is contained in:
Kenneth Skovhede
2024-08-13 17:16:55 +02:00
parent dc14b2c28e
commit cfc11b904a
2 changed files with 84 additions and 2 deletions
+82
View File
@@ -0,0 +1,82 @@
using Duplicati.Library.Logging;
using Duplicati.Server;
namespace Duplicati.WebserverCore.Dto;
/// <summary>
/// DTO entry for reporting a log entry
/// </summary>
public sealed record LogEntry
{
/// <summary>
/// The time the message was logged
/// </summary>
public required DateTime When { get; init; }
/// <summary>
/// The ID assigned to the message
/// </summary>
public required long ID { get; init; }
/// <summary>
/// The logged message
/// </summary>
public required string Message { get; init; }
/// <summary>
/// The log tag
/// </summary>
public required string Tag { get; init; }
/// <summary>
/// The message ID
/// </summary>
public required string MessageID { get; init; }
/// <summary>
/// The message ID
/// </summary>
public required string ExceptionID { get; init; }
/// <summary>
/// The message type
/// </summary>
public required LogMessageType Type { get; init; }
/// <summary>
/// Exception data attached to the message
/// </summary>
public required Exception Exception { get; init; }
/// <summary>
/// The backup ID, if any
/// </summary>
public required string BackupID { get; init; }
/// <summary>
/// The task ID, if any
/// </summary>
public required string TaskID { get; init; }
/// <summary>
/// Convert the internal record to a DTO record
/// </summary>
/// <param name="entry">The internal record</param>
/// <returns>The DTO record</returns>
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
};
}
}
@@ -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<Dictionary<string, object>>? ExecuteGetLog(Connection connection, long? offset, long pagesize)