Skip to content

Commit 1409cc1

Browse files
authored
Make connection logs less spammy (#566)
1 parent 9ac8fba commit 1409cc1

File tree

1 file changed

+7
-2
lines changed
  • src/commonMain/kotlin/fr/acinq/lightning/io

1 file changed

+7
-2
lines changed

src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ data class PeerConnection(val id: Long, val output: Channel<LightningMessage>, v
5151
// We can safely use trySend because we use unlimited channel buffers.
5252
// If the connection was closed, the message will automatically be dropped.
5353
val result = output.trySend(msg)
54-
result.onFailure { failure -> logger.warning(failure) { "cannot send $msg" } }
54+
result.onFailure { failure ->
55+
when (msg) {
56+
is Ping -> logger.warning { "cannot send $msg: ${failure?.message}" } // no need to display the full stack trace for pings, they will spam the logs when user is disconnected
57+
else -> logger.warning(failure) { "cannot send $msg" }
58+
}
59+
}
5560
}
5661
}
5762

@@ -363,7 +368,7 @@ class Peer(
363368
val job = launch {
364369
fun closeSocket(ex: TcpSocket.IOException?) {
365370
if (_connectionState.value is Connection.CLOSED) return
366-
logger.warning(ex) { "closing TCP socket: " }
371+
logger.warning { "closing TCP socket: ${ex?.message}" }
367372
socket.close()
368373
_connectionState.value = Connection.CLOSED(ex)
369374
cancel()

0 commit comments

Comments
 (0)