-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
78 lines (71 loc) · 2.38 KB
/
Logger.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ForestForTheFlames
{
internal class Logger
{
internal enum LEVEL
{
DEBUG,
INFO,
WARNING,
ERROR,
FATAL
}
public static readonly Logger Instance = new Logger();
public static void Log(LEVEL level, string caller, object msg)
{
Console.WriteLine($"[{level}] {caller}: {msg}");
}
public static void Log(object msg)
{
Log(LEVEL.INFO, new StackTrace().GetFrame(1).GetMethod().DeclaringType.FullName + "::" + new StackTrace().GetFrame(1).GetMethod().Name, msg);
}
public static void Look(object obj)
{
if (obj != null)
{
var fn = "";
foreach (var f in obj.GetType().GetRuntimeFields())
{
fn += $"[{f.FieldType.FullName}] {f.Name}: {f.GetValue(obj)}\n";
}
Log(LEVEL.DEBUG, new StackTrace().GetFrame(1).GetMethod().DeclaringType.FullName + "::" + new StackTrace().GetFrame(1).GetMethod().Name, fn);
} else
{
Log("null @ Look");
}
}
public static void Look(Type obj)
{
if (obj != null)
{
var fn = $"Field Dump of {obj.FullName}\n";
foreach (var f in obj.GetRuntimeFields())
{
if (f.IsStatic)
{
//Log($"get_{f.Name}");
// NativeFieldInfoPtr_
var m = obj.GetMethod($"get_{f.Name.Substring(19)}");
if (m != null)
{
fn += $"[{f.FieldType.FullName}] {f.Name}: {m.Invoke(obj, null)}\n";
}
//fn += $"[{f.FieldType.FullName}] {f.Name}: {f.GetValue(obj)}\n";
}
}
Log(LEVEL.DEBUG, new StackTrace().GetFrame(1).GetMethod().DeclaringType.FullName + "::" + new StackTrace().GetFrame(1).GetMethod().Name, fn);
}
else
{
Log("null @ Look [Type]");
}
}
}
}