forked from Caraxi/SimpleTweaksPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleLog.cs
75 lines (60 loc) · 3.55 KB
/
SimpleLog.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
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Dalamud.Logging;
namespace SimpleTweaksPlugin {
public static class SimpleLog {
#if DEBUG
private static int _subStrIndex;
public static void SetupBuildPath([CallerFilePath] string callerPath = "") {
var p = Path.GetDirectoryName(callerPath);
if (p != null) _subStrIndex = p.Length + 1;
}
public static void Verbose(object message, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerName = "", [CallerLineNumber] int lineNumber = -1) {
foreach (var m in SplitMessage(message)) PluginLog.LogVerbose($"[{callerPath.Substring(_subStrIndex)}::{callerName}:{lineNumber}] {m}");
}
public static void Debug(object message, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerName = "", [CallerLineNumber] int lineNumber = -1) {
foreach (var m in SplitMessage(message)) PluginLog.LogDebug($"[{callerPath.Substring(_subStrIndex)}::{callerName}:{lineNumber}] {m}");
}
public static void Information(object message, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerName = "", [CallerLineNumber] int lineNumber = -1) {
foreach (var m in SplitMessage(message)) PluginLog.LogInformation($"[{callerPath.Substring(_subStrIndex)}::{callerName}:{lineNumber}] {message}");
}
public static void Fatal(object message, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerName = "", [CallerLineNumber] int lineNumber = -1) {
foreach (var m in SplitMessage(message)) PluginLog.LogFatal($"[{callerPath.Substring(_subStrIndex)}::{callerName}:{lineNumber}] {m}");
}
public static void Log(object message, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerName = "", [CallerLineNumber] int lineNumber = -1) {
foreach (var m in SplitMessage(message)) PluginLog.Log($"[{callerPath.Substring(_subStrIndex)}::{callerName}:{lineNumber}] {m}");
}
public static void Error(object message, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerName = "", [CallerLineNumber] int lineNumber = -1) {
foreach (var m in SplitMessage(message)) PluginLog.Error($"[{callerPath.Substring(_subStrIndex)}::{callerName}:{lineNumber}] {m}");
}
#else
public static void Verbose(object message) {
foreach(var m in SplitMessage(message)) PluginLog.LogVerbose($"{m}");
}
public static void Debug(object message) {
foreach (var m in SplitMessage(message)) PluginLog.LogDebug($"{m}");
}
public static void Information(object message) {
foreach (var m in SplitMessage(message)) PluginLog.LogInformation($"{m}");
}
public static void Fatal(object message) {
foreach (var m in SplitMessage(message)) PluginLog.LogFatal($"{m}");
}
public static void Log(object message) {
foreach (var m in SplitMessage(message)) PluginLog.Log($"{m}");
}
public static void Error(object message) {
foreach (var m in SplitMessage(message)) PluginLog.Error($"{m}");
}
#endif
private static IEnumerable<string> SplitMessage(object message) {
if (message is IList list) {
return list.Cast<object>().Select((t, i) => $"{i}: {t}");
}
return $"{message}".Split('\n');
}
}
}