Skip to content

Commit

Permalink
Wrap in statement to only log once, change level to warn
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Feb 8, 2024
1 parent a61885d commit 4cfbb1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ class LavalinkSocket(private val node: LavalinkNode) : WebSocketListener(), Clos
}

is ConnectException -> {
logger.error("Failed to connect to WS of ${node.name} (${node.baseUri}), retrying in ${reconnectInterval / 1000} seconds")
logger.trace("Failed to connect to WS of ${node.name} (${node.baseUri}), retrying in ${reconnectInterval / 1000} seconds", t)
logger.warnOrTrace("Failed to connect to WS of ${node.name} (${node.baseUri}), retrying in ${reconnectInterval / 1000} seconds", t)
}

is SocketException -> {
Expand All @@ -153,8 +152,7 @@ class LavalinkSocket(private val node: LavalinkNode) : WebSocketListener(), Clos
return
}

logger.error("Socket error on ${node.name}, reconnecting in ${reconnectInterval / 1000} seconds")
logger.trace("Socket error on ${node.name}, reconnecting in ${reconnectInterval / 1000} seconds", t)
logger.warnOrTrace("Socket error on ${node.name}, reconnecting in ${reconnectInterval / 1000} seconds", t)
node.available = false
open = false
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/kotlin/dev/arbjerg/lavalink/internal/logging.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.arbjerg.lavalink.internal

import org.slf4j.Logger

/**
* Log a trace message to the console.
* If [Logger.isTraceEnabled] returns false, it will log [message] as warning instead.
*/
fun Logger.warnOrTrace(message: String, t: Throwable) {
if (this.isTraceEnabled) {
this.trace(message, t)
} else {
this.warn(message)
}
}

0 comments on commit 4cfbb1e

Please sign in to comment.