mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
38 lines
940 B
C#
38 lines
940 B
C#
using System.Collections.Generic;
|
|
using Robust.Shared.Log;
|
|
using Serilog.Events;
|
|
|
|
namespace Robust.UnitTesting
|
|
{
|
|
/// <summary>
|
|
/// Utility class for testing that logs are indeed being thrown.
|
|
/// </summary>
|
|
public sealed class LogCatcher : ILogHandler
|
|
{
|
|
/// <summary>
|
|
/// Read only list of every log message that was caught since the last flush.
|
|
/// </summary>
|
|
public IReadOnlyList<LogEvent> CaughtLogs => _logs;
|
|
private readonly List<LogEvent> _logs = new();
|
|
|
|
/// <summary>
|
|
/// Clears all currently caught logs
|
|
/// </summary>
|
|
public void Flush()
|
|
{
|
|
lock (_logs)
|
|
{
|
|
_logs.Clear();
|
|
}
|
|
}
|
|
|
|
void ILogHandler.Log(string sawmillName, LogEvent message)
|
|
{
|
|
lock (_logs)
|
|
{
|
|
_logs.Add(message);
|
|
}
|
|
}
|
|
}
|
|
}
|