5
5
6
6
namespace KSPBuildTools
7
7
{
8
- internal static class Log
9
- {
10
- internal static string Prefix = "[" + Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name + "] " ;
8
+ interface ILogContextProvider {
9
+ string context ( ) ;
10
+ }
11
+ internal static class Log
12
+ {
13
+ internal static string ModPrefix = "[" + Assembly . GetExecutingAssembly ( ) . GetName ( ) . Name + "]" ;
14
+
15
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
16
+ private static string ObjPrefix ( this UnityEngine . Object obj )
17
+ {
18
+ return "[" + obj . name + "]" ;
19
+ }
20
+
21
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
22
+ private static string ObjPrefix ( this ILogContextProvider obj )
23
+ {
24
+ return "[" + obj . context ( ) + "]" ;
25
+ }
11
26
12
27
[ System . Diagnostics . Conditional ( "DEBUG" ) ]
13
- internal static void Debug ( string message )
28
+ internal static void Debug ( string message , string prefix = "" ) {
29
+ UnityEngine . Debug . Log ( "[DEBUG]" + ModPrefix + prefix + " " + message ) ;
30
+ }
31
+
32
+ [ System . Diagnostics . Conditional ( "DEBUG" ) ]
33
+ internal static void LogDebug ( this UnityEngine . Object obj , string message , string prefix = "" ) {
34
+ UnityEngine . Debug . Log ( "[DEBUG]" + ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message , obj ) ;
35
+ }
36
+
37
+ [ System . Diagnostics . Conditional ( "DEBUG" ) ]
38
+ internal static void LogDebug ( this ILogContextProvider obj , string message , string prefix = "" ) {
39
+ UnityEngine . Debug . Log ( "[DEBUG]" + ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message ) ;
40
+ }
41
+
42
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
43
+ internal static void Message ( string message , string prefix = "" )
14
44
{
15
- UnityEngine . Debug . Log ( Prefix + message ) ;
45
+ UnityEngine . Debug . Log ( ModPrefix + prefix + " " + message ) ;
16
46
}
17
47
18
48
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
19
- internal static void Message ( string message )
49
+ internal static void LogMessage ( this UnityEngine . Object obj , string message , string prefix = "" )
20
50
{
21
- UnityEngine . Debug . Log ( Prefix + message ) ;
51
+ UnityEngine . Debug . Log ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message , obj ) ;
22
52
}
23
53
54
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
55
+ internal static void LogMessage ( this ILogContextProvider obj , string message , string prefix = "" )
56
+ {
57
+ UnityEngine . Debug . Log ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message ) ;
58
+ }
59
+
24
60
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
25
- internal static void Warning ( string message )
61
+ internal static void Warning ( string message , string prefix = "" )
26
62
{
27
- UnityEngine . Debug . LogWarning ( Prefix + message ) ;
63
+ UnityEngine . Debug . LogWarning ( ModPrefix + prefix + " " + message ) ;
28
64
}
29
65
30
66
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
31
- internal static void Error ( string message )
67
+ internal static void LogWarning ( this UnityEngine . Object obj , string message , string prefix = "" )
32
68
{
33
- UnityEngine . Debug . LogError ( Prefix + message ) ;
69
+ UnityEngine . Debug . LogWarning ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message , obj ) ;
34
70
}
35
71
72
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
73
+ internal static void LogWarning ( this ILogContextProvider obj , string message , string prefix = "" )
74
+ {
75
+ UnityEngine . Debug . LogWarning ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message ) ;
76
+ }
77
+
78
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
79
+ internal static void Error ( string message , string prefix = "" )
80
+ {
81
+ UnityEngine . Debug . LogError ( ModPrefix + prefix + " " + message ) ;
82
+ }
83
+
84
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
85
+ internal static void LogError ( UnityEngine . Object obj , string message , string prefix = "" )
86
+ {
87
+ UnityEngine . Debug . LogError ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message , obj ) ;
88
+ }
89
+
90
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
91
+ internal static void LogError ( this ILogContextProvider obj , string message , string prefix = "" )
92
+ {
93
+ UnityEngine . Debug . LogError ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message ) ;
94
+ }
95
+
36
96
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
37
97
internal static void Exception ( Exception ex )
38
98
{
39
99
UnityEngine . Debug . LogException ( ex ) ;
40
100
}
41
101
}
42
- }
102
+ }
0 commit comments