2022-05-06 21:44:25 -07:00
|
|
|
|
using OWML.Common;
|
2020-09-16 17:51:58 +01:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
2020-02-14 22:14:24 +01:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.Utility;
|
|
|
|
|
|
|
|
|
|
public static class DebugLog
|
2020-02-15 20:48:02 +01:00
|
|
|
|
{
|
2022-06-06 23:35:13 -07:00
|
|
|
|
public static readonly int ProcessInstanceId = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)
|
2022-05-06 21:44:25 -07:00
|
|
|
|
.IndexOf(x => x.Id == Process.GetCurrentProcess().Id);
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public static void ToConsole(string message, MessageType type = MessageType.Message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2022-05-06 21:44:25 -07:00
|
|
|
|
if (QSBCore.DebugSettings.InstanceIdInLogs)
|
2022-01-18 01:46:41 -08:00
|
|
|
|
{
|
2022-06-06 23:35:13 -07:00
|
|
|
|
message = $"[{ProcessInstanceId}] " + message;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-08-10 18:17:54 +02:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
QSBCore.Helper.Console.WriteLine(message, type, GetCallingType(new StackTrace()));
|
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public static void ToHud(string message)
|
|
|
|
|
{
|
|
|
|
|
if (Locator.GetPlayerBody() == null)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
return;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2022-02-24 22:04:54 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
var data = new NotificationData(NotificationTarget.Player, message.ToUpper());
|
|
|
|
|
NotificationManager.SharedInstance.PostNotification(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ToAll(string message, MessageType type = MessageType.Message)
|
|
|
|
|
{
|
|
|
|
|
ToConsole(message, type);
|
|
|
|
|
ToHud(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void DebugWrite(string message, MessageType type = MessageType.Message)
|
|
|
|
|
{
|
|
|
|
|
if (QSBCore.DebugSettings.DebugMode)
|
2022-02-27 04:40:44 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
ToConsole(message, type);
|
2022-02-27 04:40:44 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
|
|
|
|
|
private static string GetCallingType(StackTrace frame) =>
|
|
|
|
|
frame.GetFrames()!
|
|
|
|
|
.Select(x => x.GetMethod().DeclaringType!.Name)
|
|
|
|
|
.First(x => x != nameof(DebugLog));
|
2022-05-06 21:44:25 -07:00
|
|
|
|
}
|