-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebugTools.cs
42 lines (37 loc) · 1.26 KB
/
DebugTools.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using UnityEngine;
namespace kOS.AddOns.kOSAstrogator
{
/// Tools to help with debugging. Copied from Astrogator.DebugTools, but with our own name.
public static class DebugTools {
private static readonly object debugMutex = new object();
/// <summary>
/// Add a formattable string to the debug output.
/// Automatically prepends the mod name and a timestamp.
/// </summary>
/// <param name="format">String.Format format string</param>
/// <param name="args">Parameters for the format string, if any</param>
[System.Diagnostics.Conditional("DEBUG")]
public static void DbgFmt(string format, params object[] args)
{
string formattedMessage = string.Format(format, args);
lock (debugMutex) {
MonoBehaviour.print($"[{KOSAstrogatorAddon.Name} {Time.realtimeSinceStartup:000.000}] {formattedMessage}");
}
}
/// <summary>
/// Log a debug message about an Exception
/// </summary>
/// <param name="description">Explanation of the context in which the exception was raised</param>
/// <param name="ex">The exception to log</param>
[System.Diagnostics.Conditional("DEBUG")]
public static void DbgExc(string description, Exception ex) {
DbgFmt(
"{0}: {1}\n{2}",
description,
ex.Message,
ex.StackTrace
);
}
}
}