Skip to content

Commit

Permalink
implement HTTP request logging
Browse files Browse the repository at this point in the history
  • Loading branch information
paulchen committed Jan 1, 2024
1 parent 4d0f94b commit 20751e9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ dependencies {
implementation("io.ktor:ktor-client-websockets:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/at/rueckgr/kotlin/rocketbot/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import at.rueckgr.kotlin.rocketbot.websocket.ConnectMessage
import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.logging.*
import io.ktor.client.plugins.websocket.*
import io.ktor.http.*
import io.ktor.websocket.*
Expand Down Expand Up @@ -64,6 +65,12 @@ class Bot(private val botConfiguration: BotConfiguration,
try {
val client = HttpClient(CIO) {
install(WebSockets)
if (botConfiguration.logRequests) {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
}
}
client.wss(
method = HttpMethod.Get,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ data class BotConfiguration(
val password: String,
val ignoredChannels: List<String>,
val botId: String,
val webservicePort: Int
val webservicePort: Int,
val logRequests: Boolean
)

0 comments on commit 20751e9

Please sign in to comment.