Skip to content

Commit

Permalink
feat(libp2p): #41 improve logging (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
chertby authored Sep 26, 2023
1 parent a303ca9 commit 1c89601
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/libp2p/Libp2p/LogMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: MIT

using Microsoft.Extensions.Logging;

namespace Nethermind.Libp2p.Stack;

internal static partial class LogMessages
{
[LoggerMessage(
Message = "{protocol} has been picked to {action}",
Level = LogLevel.Debug)]
internal static partial void LogPickedProtocol(
this ILogger logger,
string protocol,
string action);
}
3 changes: 2 additions & 1 deletion src/libp2p/Libp2p/MultiaddrBasedSelectorProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.Extensions.Logging;
using Nethermind.Libp2p.Core;
using Nethermind.Libp2p.Stack;

namespace Nethermind.Libp2p.Protocols;

Expand All @@ -21,7 +22,7 @@ protected override async Task ConnectAsync(IChannel _, IChannelFactory? channelF
channelFactory!.SubProtocols.FirstOrDefault(proto => proto.Id.Contains("quic")) ?? throw new ApplicationException("QUIC is not supported") :
channelFactory!.SubProtocols.FirstOrDefault(proto => proto.Id.Contains("tcp")) ?? throw new ApplicationException("TCP is not supported");

_logger?.LogDebug("{protocol} has been picked to {action}", protocol.Id, isListener ? "listen" : "dial");
_logger?.LogPickedProtocol(protocol.Id, isListener ? "listen" : "dial");

await (isListener
? channelFactory.SubListen(context, protocol)
Expand Down

0 comments on commit 1c89601

Please sign in to comment.