Files
RobustToolbox/Robust.UnitTesting/TestLogHandler.cs
T
AcruidandGitHub 2183cd7ca1 Massive Namespace Cleanup (#1544)
* Removed the Interfaces folder.
* All objects inside the GameObjects subfolders are now in the GameObjects namespace.
* Added a Resharper DotSettings file to mark the GameObjects subfolders as not providing namespaces.
* Simplified Robust.client.Graphics namespace.
* Automated remove redundant using statements.
2021-02-10 23:27:19 -08:00

43 lines
1.0 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using NUnit.Framework;
using Robust.Shared.Log;
using Serilog.Events;
namespace Robust.UnitTesting
{
public sealed class TestLogHandler : ILogHandler, IDisposable
{
private readonly string _prefix;
private readonly TextWriter _writer;
private readonly Stopwatch _sw = Stopwatch.StartNew();
public TestLogHandler(string prefix)
{
_prefix = prefix;
_writer = TestContext.Out;
_writer.WriteLine($"{_prefix}: Started {DateTime.Now:o}");
}
public void Dispose()
{
_writer.Dispose();
}
public void Log(string sawmillName, LogEvent message)
{
var name = LogMessage.LogLevelToName(message.Level.ToRobust());
var seconds = _sw.ElapsedMilliseconds/1000d;
var rendered = message.RenderMessage();
_writer.WriteLine($"{_prefix}: {seconds:F3}s [{name}] {sawmillName}: {rendered}");
}
}
}