55
66namespace KSPBuildTools
77{
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+ }
1126
1227 [ 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 = "" )
1444 {
15- UnityEngine . Debug . Log ( Prefix + message ) ;
45+ UnityEngine . Debug . Log ( ModPrefix + prefix + " " + message ) ;
1646 }
1747
1848 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
19- internal static void Message ( string message )
49+ internal static void LogMessage ( this UnityEngine . Object obj , string message , string prefix = "" )
2050 {
21- UnityEngine . Debug . Log ( Prefix + message ) ;
51+ UnityEngine . Debug . Log ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message , obj ) ;
2252 }
2353
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+
2460 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
25- internal static void Warning ( string message )
61+ internal static void Warning ( string message , string prefix = "" )
2662 {
27- UnityEngine . Debug . LogWarning ( Prefix + message ) ;
63+ UnityEngine . Debug . LogWarning ( ModPrefix + prefix + " " + message ) ;
2864 }
2965
3066 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
31- internal static void Error ( string message )
67+ internal static void LogWarning ( this UnityEngine . Object obj , string message , string prefix = "" )
3268 {
33- UnityEngine . Debug . LogError ( Prefix + message ) ;
69+ UnityEngine . Debug . LogWarning ( ModPrefix + obj . ObjPrefix ( ) + prefix + " " + message , obj ) ;
3470 }
3571
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+
3696 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3797 internal static void Exception ( Exception ex )
3898 {
3999 UnityEngine . Debug . LogException ( ex ) ;
40100 }
41101 }
42- }
102+ }
0 commit comments