Skip to content

Commit

Permalink
Updated defaultLogger to create a singleTon, updated realtimeClient with
Browse files Browse the repository at this point in the history
testSink
  • Loading branch information
sacOO7 committed Aug 12, 2023
1 parent 13a0940 commit 893f12e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@ namespace IO.Ably.Tests.Shared.Helpers
/// <summary>An utility class for logging various messages.</summary>
public static class DefaultLogger
{
internal static ILogger LoggerInstance => InternalLogger.Create();
private static readonly object SyncLock = new object();
private static ILogger _loggerInstance;

internal static ILogger LoggerInstance
{
get
{
if (_loggerInstance == null)
{
lock (SyncLock)
{
_loggerInstance = InternalLogger.Create();
}
}

return _loggerInstance;
}

set => _loggerInstance = value;
}

/// <summary>Maximum level to log.</summary>
/// <remarks>E.g. set to LogLevel.Warning to have only errors and warnings in the log.</remarks>
Expand Down
2 changes: 1 addition & 1 deletion src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public async Task WhenDeltaDecodeFail_ShouldSetStateToAttachingLogTheErrorAndDis
var firstMessageReceived = new TaskCompletionAwaiter();
using (((IInternalLogger)Logger).CreateDisposableLoggingContext(testSink))
{
var realtime = await GetRealtimeClient(protocol);
var realtime = await GetRealtimeClient(protocol, (options, _) => options.LogHandler = testSink);
var channel = realtime.Channels.Get(channelName, new ChannelOptions(channelParams: new ChannelParams { { "delta", "vcdiff" } }));

var received = new List<Message>();
Expand Down

0 comments on commit 893f12e

Please sign in to comment.