quantum-space-buddies/QSB/Utility/DebugLog.cs

42 lines
1.1 KiB
C#
Raw Normal View History

2020-08-21 13:04:13 +00:00
using OWML.Common;
2020-09-16 16:51:58 +00:00
using System.Diagnostics;
using System.Linq;
namespace QSB.Utility
2020-02-15 19:48:02 +00:00
{
2020-12-02 21:23:01 +00:00
public static class DebugLog
{
2020-12-20 18:16:23 +00:00
public static void ToConsole(string message, MessageType type = MessageType.Message)
2020-12-20 16:48:04 +00:00
=> QSBCore.Helper.Console.WriteLine(message, type, GetCallingType(new StackTrace()));
2020-12-02 21:23:01 +00:00
public static void ToHud(string message)
{
if (Locator.GetPlayerBody() == null)
{
return;
}
var data = new NotificationData(NotificationTarget.Player, message.ToUpper());
NotificationManager.SharedInstance.PostNotification(data);
}
2020-02-15 19:48:02 +00:00
2020-12-02 21:23:01 +00:00
public static void ToAll(string message, MessageType type = MessageType.Message)
{
ToConsole(message, type);
ToHud(message);
}
2020-08-10 16:17:54 +00:00
2020-12-02 21:23:01 +00:00
public static void DebugWrite(string message, MessageType type = MessageType.Message)
{
2020-12-14 16:24:52 +00:00
if (QSBCore.DebugMode)
2020-12-02 21:23:01 +00:00
{
ToConsole(message, type);
}
}
2020-08-22 19:21:13 +00:00
2020-12-02 21:23:01 +00:00
private static string GetCallingType(StackTrace frame)
{
var stackFrame = frame.GetFrames().First(x => x.GetMethod().DeclaringType.Name != "DebugLog");
return stackFrame.GetMethod().DeclaringType.Name;
}
}
2020-12-03 08:28:05 +00:00
}