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>
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Robust.Client.Console;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Utility;
|
|
using Serilog.Events;
|
|
|
|
namespace Robust.Client.Log
|
|
{
|
|
/// <summary>
|
|
/// Writes logs to the in-game debug console.
|
|
/// </summary>
|
|
sealed class DebugConsoleLogHandler : ILogHandler
|
|
{
|
|
readonly IClientConsoleHost Console;
|
|
|
|
public DebugConsoleLogHandler(IClientConsoleHost console)
|
|
{
|
|
Console = console;
|
|
}
|
|
|
|
public void Log(string sawmillName, LogEvent message)
|
|
{
|
|
if (sawmillName == "CON")
|
|
return;
|
|
|
|
var formatted = new FormattedMessage(8);
|
|
var robustLevel = message.Level.ToRobust();
|
|
formatted.PushColor(Color.DarkGray);
|
|
formatted.AddText("[");
|
|
formatted.PushColor(LogLevelToColor(robustLevel));
|
|
formatted.AddText(LogMessage.LogLevelToName(robustLevel));
|
|
formatted.Pop();
|
|
formatted.AddText($"] {sawmillName}: ");
|
|
formatted.Pop();
|
|
formatted.AddText(message.RenderMessage());
|
|
if (message.Exception != null)
|
|
{
|
|
formatted.AddText("\n");
|
|
formatted.AddText(message.Exception.ToString());
|
|
}
|
|
Console.AddFormattedLine(formatted);
|
|
}
|
|
|
|
private static Color LogLevelToColor(LogLevel level)
|
|
{
|
|
return level switch
|
|
{
|
|
LogLevel.Verbose => Color.Green,
|
|
LogLevel.Debug => Color.Blue,
|
|
LogLevel.Info => Color.Cyan,
|
|
LogLevel.Warning => Color.Yellow,
|
|
LogLevel.Error => Color.Red,
|
|
LogLevel.Fatal => Color.Red,
|
|
_ => Color.White
|
|
};
|
|
}
|
|
}
|
|
}
|