Skip to content

Commit 00c6155

Browse files
committed
Consolidate redundant logging configuration method.
1 parent be1ffd5 commit 00c6155

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

src/PactNet.Interop/LogLevelExtensions.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Runtime.InteropServices;
23

34
namespace PactNet.Interop;
45

@@ -22,7 +23,7 @@ public static void InitialiseLogging(this PactLogLevel level)
2223
return;
2324
}
2425

25-
NativeInterop.LogToBuffer(level switch
26+
LoggingInterop.LogToBuffer(level switch
2627
{
2728
PactLogLevel.Trace => LevelFilter.Trace,
2829
PactLogLevel.Debug => LevelFilter.Debug,
@@ -35,5 +36,14 @@ public static void InitialiseLogging(this PactLogLevel level)
3536

3637
LogInitialised = true;
3738
}
39+
40+
}
41+
42+
private static class LoggingInterop
43+
{
44+
private const string DllName = "pact_ffi";
45+
46+
[DllImport(DllName, EntryPoint = "pactffi_log_to_buffer")]
47+
public static extern int LogToBuffer(LevelFilter levelFilter);
3848
}
3949
}

src/PactNet.Interop/NativeInterop.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ public static class NativeInterop
1010
{
1111
private const string DllName = "pact_ffi";
1212

13-
[DllImport(DllName, EntryPoint = "pactffi_log_to_buffer")]
14-
public static extern int LogToBuffer(LevelFilter levelFilter);
15-
1613
#region Http Interop Support
1714

1815
[DllImport(DllName, EntryPoint = "pactffi_fetch_log_buffer")]

src/PactNet/Verifier/InteropVerifierProvider.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,7 @@ public InteropVerifierProvider(PactVerifierConfig config)
3131
/// </summary>
3232
public void Initialise()
3333
{
34-
NativeInterop.LogToBuffer(config.LogLevel switch
35-
{
36-
PactLogLevel.Trace => LevelFilter.Trace,
37-
PactLogLevel.Debug => LevelFilter.Debug,
38-
PactLogLevel.Information => LevelFilter.Info,
39-
PactLogLevel.Warn => LevelFilter.Warn,
40-
PactLogLevel.Error => LevelFilter.Error,
41-
PactLogLevel.None => LevelFilter.Off,
42-
_ => throw new ArgumentOutOfRangeException(nameof(config.LogLevel), config.LogLevel, "Invalid log level")
43-
});
44-
34+
config.LogLevel.InitialiseLogging();
4535
this.handle = NativeInterop.VerifierNewForApplication("pact-net", typeof(InteropVerifierProvider).Assembly.GetName().Version.ToString());
4636
}
4737

tests/PactNet.Tests/Drivers/FfiIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public FfiIntegrationTests(ITestOutputHelper output)
2323
{
2424
this.output = output;
2525

26-
NativeInterop.LogToBuffer(LevelFilter.Trace);
26+
PactLogLevel.Trace.InitialiseLogging();
2727
}
2828

2929
[Fact]
@@ -36,7 +36,7 @@ public async Task HttpInteraction_v3_CreatesPactFile()
3636
IHttpPactDriver pact = driver.NewHttpPact("NativeDriverTests-Consumer-V3",
3737
"NativeDriverTests-Provider",
3838
PactSpecification.V3);
39-
39+
4040
IHttpInteractionDriver interaction = pact.NewHttpInteraction("a sample interaction");
4141

4242
interaction.Given("provider state");

0 commit comments

Comments
 (0)