Files
RobustToolbox/Robust.Client/Log/DebugConsoleLogHandler.cs
Acruid 3eb6e067f9 Console Unify (#1513)
* Renamed shared ICommand to IConsoleCommand.

* Lots of refactoring into a shared context.

* Removed ICommonSession from server concmd Execute.

* Added argStr parameter to concmd execute.

* The execute function of client concmds now returns void, use the new shell.RemoteExecuteCommand function to forward commands.

# Conflicts:
#	Robust.Client/Console/Commands/Debug.cs

* Finally move shells and commands into shared.

* Console commands can now be registered directly without a class in a shared context.

* Pulled up ConsoleHost and Console shell into a shared context.

* Pulled up half the functions of ConsoleHost into a shared context.

* Repair rebase damage.

* Make LoadConsoleCommands function not remove any previously registered commands.
2021-02-01 16:40:26 -08:00

57 lines
1.7 KiB
C#

using Robust.Client.Console;
using Robust.Shared.Interfaces.Log;
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>
class DebugConsoleLogHandler : ILogHandler
{
readonly IClientConsoleHost Console;
public DebugConsoleLogHandler(IClientConsoleHost console)
{
Console = console;
}
public void Log(string sawmillName, LogEvent message)
{
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
};
}
}
}