Skip to content

Commit

Permalink
reduce log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
mus65 committed Dec 1, 2024
1 parent 534b1c8 commit 3e46405
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Renci.SshNet/BaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ protected virtual void Dispose(bool disposing)

if (disposing)
{
_logger.LogInformation("Disposing client.");
_logger.LogDebug("Disposing client.");

Disconnect();

Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Channels/ChannelDirectTcpip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void ShutdownSocket(SocketShutdown how)
}
catch (SocketException ex)
{
_logger.LogWarning(ex, "Failure shutting down socket");
_logger.LogInformation(ex, "Failure shutting down socket");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void ShutdownSocket(SocketShutdown how)
}
catch (SocketException ex)
{
_logger.LogWarning(ex, "Failure shutting down socket");
_logger.LogInformation(ex, "Failure shutting down socket");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/ForwardedPortDynamic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private void InternalStop(TimeSpan timeout)

if (!_pendingChannelCountdown.Wait(timeout))
{
_logger.LogWarning("Timeout waiting for pending channels in dynamic forwarded port to close.");
_logger.LogInformation("Timeout waiting for pending channels in dynamic forwarded port to close.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/ForwardedPortLocal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private void InternalStop(TimeSpan timeout)

if (!_pendingChannelCountdown.Wait(timeout))
{
_logger.LogWarning("Timeout waiting for pending channels in local forwarded port to close.");
_logger.LogInformation("Timeout waiting for pending channels in local forwarded port to close.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/ForwardedPortRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected override void StopPort(TimeSpan timeout)

if (!_pendingChannelCountdown.Wait(timeout))
{
_logger.LogWarning("Timeout waiting for pending channels in remote forwarded port to close.");
_logger.LogInformation("Timeout waiting for pending channels in remote forwarded port to close.");
}

_status = ForwardedPortStatus.Stopped;
Expand Down
12 changes: 6 additions & 6 deletions src/Renci.SshNet/Security/KeyExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public Cipher CreateServerCipher(out bool isAead)

serverKey = GenerateSessionKey(SharedKey, ExchangeHash, serverKey, _serverCipherInfo.KeySize / 8);

_logger.LogInformation("[{SessionId}] Creating {ServerEncryption} server cipher.",
_logger.LogDebug("[{SessionId}] Creating {ServerEncryption} server cipher.",
Session.SessionIdHex,
Session.ConnectionInfo.CurrentServerEncryption);

Expand Down Expand Up @@ -225,7 +225,7 @@ public Cipher CreateClientCipher(out bool isAead)

clientKey = GenerateSessionKey(SharedKey, ExchangeHash, clientKey, _clientCipherInfo.KeySize / 8);

_logger.LogInformation("[{SessionId}] Creating {ClientEncryption} client cipher.",
_logger.LogDebug("[{SessionId}] Creating {ClientEncryption} client cipher.",
Session.SessionIdHex,
Session.ConnectionInfo.CurrentClientEncryption);

Expand Down Expand Up @@ -258,7 +258,7 @@ public HashAlgorithm CreateServerHash(out bool isEncryptThenMAC)
Hash(GenerateSessionKey(SharedKey, ExchangeHash, 'F', sessionId)),
_serverHashInfo.KeySize / 8);

_logger.LogInformation("[{SessionId}] Creating {ServerHmacAlgorithm} server hmac algorithm.",
_logger.LogDebug("[{SessionId}] Creating {ServerHmacAlgorithm} server hmac algorithm.",
Session.SessionIdHex,
Session.ConnectionInfo.CurrentServerHmacAlgorithm);

Expand Down Expand Up @@ -290,7 +290,7 @@ public HashAlgorithm CreateClientHash(out bool isEncryptThenMAC)
Hash(GenerateSessionKey(SharedKey, ExchangeHash, 'E', sessionId)),
_clientHashInfo.KeySize / 8);

_logger.LogInformation("[{SessionId}] Creating {ClientHmacAlgorithm} client hmac algorithm.",
_logger.LogDebug("[{SessionId}] Creating {ClientHmacAlgorithm} client hmac algorithm.",
Session.SessionIdHex,
Session.ConnectionInfo.CurrentClientHmacAlgorithm);

Expand All @@ -310,7 +310,7 @@ public Compressor CreateCompressor()
return null;
}

_logger.LogInformation("[{SessionId}] Creating {CompressionAlgorithm} client compressor.",
_logger.LogDebug("[{SessionId}] Creating {CompressionAlgorithm} client compressor.",
Session.SessionIdHex,
Session.ConnectionInfo.CurrentClientCompressionAlgorithm);

Expand All @@ -334,7 +334,7 @@ public Compressor CreateDecompressor()
return null;
}

_logger.LogInformation("[{SessionId}] Creating {ServerCompressionAlgorithm} server decompressor.",
_logger.LogDebug("[{SessionId}] Creating {ServerCompressionAlgorithm} server decompressor.",
Session.SessionIdHex,
Session.ConnectionInfo.CurrentServerCompressionAlgorithm);

Expand Down
24 changes: 15 additions & 9 deletions src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,10 @@ internal void SendMessage(Message message)
WaitOnHandle(_keyExchangeCompletedWaitHandle.WaitHandle);
}

_logger.LogInformation("[{SessionId}] Sending message '{MessageType}' to server: '{Message}'.", SessionIdHex, message.GetType().Name, message);
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("[{SessionId}] Sending message '{MessageType}' to server: '{Message}'.", SessionIdHex, message.GetType().Name, message);
}

var paddingMultiplier = _clientCipher is null ? (byte)8 : Math.Max((byte)8, _clientCipher.MinimumSize);
var packetData = message.GetPacket(paddingMultiplier, _clientCompression, _clientEtm || _clientAead);
Expand Down Expand Up @@ -1496,7 +1499,7 @@ internal void OnKeyExchangeInitReceived(KeyExchangeInitMessage message)
{
_isStrictKex = true;

_logger.LogInformation("[{SessionId}] Enabling strict key exchange extension.", SessionIdHex);
_logger.LogDebug("[{SessionId}] Enabling strict key exchange extension.", SessionIdHex);

if (_inboundPacketSequence != 1)
{
Expand All @@ -1512,7 +1515,7 @@ internal void OnKeyExchangeInitReceived(KeyExchangeInitMessage message)

ConnectionInfo.CurrentKeyExchangeAlgorithm = _keyExchange.Name;

_logger.LogInformation("[{SessionId}] Performing {KeyExchangeAlgorithm} key exchange.", SessionIdHex, ConnectionInfo.CurrentKeyExchangeAlgorithm);
_logger.LogDebug("[{SessionId}] Performing {KeyExchangeAlgorithm} key exchange.", SessionIdHex, ConnectionInfo.CurrentKeyExchangeAlgorithm);

_keyExchange.HostKeyReceived += KeyExchange_HostKeyReceived;

Expand Down Expand Up @@ -1828,7 +1831,10 @@ private Message LoadMessage(byte[] data, int offset, int count)
var message = _sshMessageFactory.Create(messageType);
message.Load(data, offset + 1, count - 1);

_logger.LogInformation("[{SessionId}] Received message '{MessageType}' from server: '{Message}'.", SessionIdHex, message.GetType().Name, message);
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("[{SessionId}] Received message '{MessageType}' from server: '{Message}'.", SessionIdHex, message.GetType().Name, message);
}

return message;
}
Expand Down Expand Up @@ -1968,7 +1974,7 @@ private void SocketDisconnectAndDispose()
{
try
{
_logger.LogInformation("[{SessionId}] Shutting down socket.", SessionIdHex);
_logger.LogDebug("[{SessionId}] Shutting down socket.", SessionIdHex);

// Interrupt any pending reads; should be done outside of socket read lock as we
// actually want shutdown the socket to make sure blocking reads are interrupted.
Expand All @@ -1980,13 +1986,13 @@ private void SocketDisconnectAndDispose()
}
catch (SocketException ex)
{
_logger.LogWarning(ex, "Failure shutting down socket");
_logger.LogInformation(ex, "Failure shutting down socket");
}
}

_logger.LogInformation("[{SessionId}] Disposing socket.", SessionIdHex);
_logger.LogDebug("[{SessionId}] Disposing socket.", SessionIdHex);
_socket.Dispose();
_logger.LogInformation("[{SessionId}] Disposed socket.", SessionIdHex);
_logger.LogDebug("[{SessionId}] Disposed socket.", SessionIdHex);
_socket = null;
}
}
Expand Down Expand Up @@ -2170,7 +2176,7 @@ protected virtual void Dispose(bool disposing)

if (disposing)
{
_logger.LogInformation("[{SessionId}] Disposing session.", SessionIdHex);
_logger.LogDebug("[{SessionId}] Disposing session.", SessionIdHex);

Disconnect();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static IntegrationTestBase()
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder.SetMinimumLevel(LogLevel.Debug);
builder.SetMinimumLevel(LogLevel.Information);
builder.AddConsole();
});

Expand Down

0 comments on commit 3e46405

Please sign in to comment.