11using System ;
22using LibGit2Sharp . Core ;
3- using LibGit2Sharp . Handlers ;
43
54namespace LibGit2Sharp
65{
@@ -11,7 +10,8 @@ public static class GlobalSettings
1110 {
1211 private static readonly Lazy < Version > version = new Lazy < Version > ( Version . Build ) ;
1312
14- private static TraceConfiguration traceConfiguration = TraceConfiguration . None ;
13+ internal static ILibGit2SharpLog internalLogger = NullLogger . Instance ;
14+ internal static TraceLevel internalMaxTraceLevel = TraceLevel . None ;
1515
1616 /// <summary>
1717 /// Returns all the optional features that were compiled into
@@ -44,7 +44,7 @@ public static Version Version
4444 /// with the server This is not commonly
4545 /// used: some callers may want to re-use an existing connection to
4646 /// perform fetch / push operations to a remote.
47- ///
47+ ///
4848 /// Note that this configuration is global to an entire process
4949 /// and does not honor application domains.
5050 /// </summary>
@@ -88,34 +88,41 @@ public static void UnregisterSmartSubtransport<T>(SmartSubtransportRegistration<
8888 registration . Free ( ) ;
8989 }
9090
91- /// <summary>
92- /// Registers a new <see cref="TraceConfiguration"/> to receive
93- /// trace information from libgit2.
94- ///
95- /// Note that this configuration is global to an entire process
96- /// and does not honor application domains.
97- /// </summary>
98- public static TraceConfiguration TraceConfiguration
91+ public static void RegisterLogger ( TraceLevel maxLevel , ILibGit2SharpLog logger )
9992 {
100- set
93+ if ( logger == null || maxLevel == TraceLevel . None )
10194 {
102- Ensure . ArgumentNotNull ( value , "value" ) ;
103-
104- traceConfiguration = value ;
105-
106- if ( traceConfiguration . Level == TraceLevel . None )
107- {
108- Proxy . git_trace_set ( 0 , null ) ;
109- }
110- else
111- {
112- Proxy . git_trace_set ( value . Level , value . GitTraceHandler ) ;
113- }
95+ // TODO: Threadsafe impl
96+ internalLogger = NullLogger . Instance ;
97+ internalMaxTraceLevel = TraceLevel . None ;
98+ Proxy . git_trace_set ( 0 , null ) ;
11499 }
115100
116- get
101+ internalLogger = logger ;
102+ internalMaxTraceLevel = maxLevel ;
103+ Proxy . git_trace_set ( maxLevel , t ) ;
104+ }
105+
106+ private static void t ( TraceLevel level , IntPtr msg )
107+ {
108+ string message = LaxUtf8Marshaler . FromNative ( msg ) ;
109+
110+ switch ( level )
117111 {
118- return traceConfiguration ;
112+ case TraceLevel . Debug :
113+ internalLogger . Debug ( message ) ;
114+ break ;
115+
116+ case TraceLevel . Info :
117+ internalLogger . Info ( message ) ;
118+ break ;
119+
120+ case TraceLevel . Error :
121+ internalLogger . Error ( message ) ;
122+ break ;
123+
124+ default :
125+ throw new InvalidOperationException ( ) ;
119126 }
120127 }
121128 }
0 commit comments