41 lines
1.1 KiB
C#
Raw Normal View History

2020-08-21 14:04:13 +01:00
using OWML.Common;
2020-09-16 17:51:58 +01:00
using System.Diagnostics;
using System.Linq;
namespace QSB.Utility
2020-02-15 20:48:02 +01:00
{
2020-12-02 21:23:01 +00:00
public static class DebugLog
{
2020-12-20 16:47:50 +00:00
public static void ToConsole(string message, MessageType type = MessageType.Message) => 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 20:48:02 +01: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 18:17:54 +02: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 20:21:13 +01: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
}