Skip to content

Commit f9e0f4b

Browse files
authored
feat: configurable debug string limit (#60)
1 parent c581013 commit f9e0f4b

File tree

6 files changed

+10
-6
lines changed

6 files changed

+10
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ To use kdriver, add the following to your `build.gradle.kts`:
4747

4848
```kotlin
4949
dependencies {
50-
implementation("dev.kdriver:core:0.5.4")
50+
implementation("dev.kdriver:core:0.5.5")
5151
}
5252
```
5353

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
allprojects {
88
group = "dev.kdriver"
9-
version = "0.5.4"
9+
version = "0.5.5"
1010
project.ext.set("url", "https://github.com/cdpdriver/kdriver")
1111
project.ext.set("license.name", "Apache 2.0")
1212
project.ext.set("license.url", "https://www.apache.org/licenses/LICENSE-2.0.txt")

core/src/commonMain/kotlin/dev/kdriver/core/browser/Config.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Config(
1818
val browserConnectionTimeout: Long = Defaults.BROWSER_CONNECTION_TIMEOUT,
1919
val browserConnectionMaxTries: Int = Defaults.BROWSER_CONNECTION_MAX_TRIES,
2020
val autoDiscoverTargets: Boolean = Defaults.AUTO_DISCOVER_TARGETS,
21+
val debugStringLimit: Int = Defaults.DEBUG_STRING_LIMIT,
2122
) {
2223

2324
private val logger = KtorSimpleLogger("Config")
@@ -118,6 +119,7 @@ class Config(
118119
const val BROWSER_CONNECTION_TIMEOUT: Long = 500
119120
const val BROWSER_CONNECTION_MAX_TRIES: Int = 60
120121
const val AUTO_DISCOVER_TARGETS: Boolean = true
122+
const val DEBUG_STRING_LIMIT: Int = 128
121123
}
122124

123125
}

core/src/commonMain/kotlin/dev/kdriver/core/browser/ConfigBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ConfigBuilder {
3030
var browserConnectionTimeout: Long = Defaults.BROWSER_CONNECTION_TIMEOUT
3131
var browserConnectionMaxTries: Int = Defaults.BROWSER_CONNECTION_MAX_TRIES
3232
var autoDiscoverTargets: Boolean = Defaults.AUTO_DISCOVER_TARGETS
33+
var debugStringLimit: Int = Defaults.DEBUG_STRING_LIMIT
3334

3435
/**
3536
* Builds the Config instance with the configured parameters.
@@ -49,6 +50,7 @@ class ConfigBuilder {
4950
browserConnectionTimeout = browserConnectionTimeout,
5051
browserConnectionMaxTries = browserConnectionMaxTries,
5152
autoDiscoverTargets = autoDiscoverTargets,
53+
debugStringLimit = debugStringLimit
5254
)
5355
}
5456
}

core/src/commonMain/kotlin/dev/kdriver/core/connection/DefaultConnection.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dev.kdriver.core.connection
33
import dev.kdriver.cdp.*
44
import dev.kdriver.cdp.domain.*
55
import dev.kdriver.core.browser.Browser
6+
import dev.kdriver.core.browser.Config.Defaults
67
import dev.kdriver.core.browser.WebSocketInfo
78
import io.ktor.client.*
89
import io.ktor.client.plugins.websocket.*
@@ -33,7 +34,6 @@ open class DefaultConnection(
3334
) : OwnedConnection {
3435

3536
private val logger = KtorSimpleLogger("Connection")
36-
private val debugStringLimit = 64
3737

3838
private val client = HttpClient(getWebSocketClientEngine()) {
3939
install(WebSockets)
@@ -82,7 +82,7 @@ open class DefaultConnection(
8282
try {
8383
frame as? Frame.Text ?: continue
8484
val text = frame.readText()
85-
logger.debug("WS < CDP: ${text.take(debugStringLimit)}")
85+
logger.debug("WS < CDP: ${text.take(owner?.config?.debugStringLimit ?: Defaults.DEBUG_STRING_LIMIT)}")
8686
val received = Serialization.json.decodeFromString<Message>(text)
8787
allMessages.emit(received)
8888
} catch (e: Exception) {
@@ -108,7 +108,7 @@ open class DefaultConnection(
108108
val requestId = currentIdMutex.withLock { currentId++ }
109109
val jsonString = Serialization.json.encodeToString(Request(requestId, method, parameter))
110110
wsSession?.send(jsonString)
111-
logger.debug("WS > CDP: ${jsonString.take(debugStringLimit)}")
111+
logger.debug("WS > CDP: ${jsonString.take(owner?.config?.debugStringLimit ?: Defaults.DEBUG_STRING_LIMIT)}")
112112

113113
val result = responses.first { it.id == requestId }
114114
result.error?.throwAsException(method)

docs/home/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To install, add the dependency to your `build.gradle.kts`:
1212

1313
```kotlin
1414
dependencies {
15-
implementation("dev.kdriver:core:0.5.4")
15+
implementation("dev.kdriver:core:0.5.5")
1616
}
1717
```
1818

0 commit comments

Comments
 (0)