Skip to content

Commit 64e5a05

Browse files
committed
docs: clarify HttpLogLevel.fromEnv layering and use enum-driven lookup
The fromEnv KDoc described env-only resolution, but the value is read through Configuration.get, which layers override -> env var -> normalized system property -> default. Note this so callers aren't surprised when a system property supplies the value. Replace the hardcoded when over level-name string literals with a lookup over HttpLogLevel.entries so a newly added enum constant resolves without a matching branch edit. Add a test pinning that a whitespace-only value falls back to the supplied default.
1 parent 7914a83 commit 64e5a05

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

sdk-core/src/main/kotlin/org/dexpace/sdk/core/http/pipeline/steps/HttpLogLevel.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ public enum class HttpLogLevel {
3737

3838
public companion object {
3939
/**
40-
* Resolves a log level from the environment-variable [key], reading through the testable
41-
* env-source seam of [source].
40+
* Resolves a log level from the configuration [key], reading through the testable
41+
* config seam of [source].
42+
*
43+
* Despite the name, resolution is not env-only: [source] is consulted via
44+
* [Configuration.get], which applies the full layering — explicit override -> environment
45+
* variable -> normalized system property -> default. So the value may legitimately come
46+
* from an override or from a system property (e.g. the key `MY_PRODUCT_LOG_LEVEL` also
47+
* matches the `my.product.log.level` system property), not strictly the environment.
4248
*
4349
* The SDK is a toolkit, not a product, so it deliberately bakes in **no** default key —
4450
* the caller (e.g. a generated client) supplies its own product's variable name, and
@@ -61,12 +67,8 @@ public enum class HttpLogLevel {
6167
default: HttpLogLevel = NONE,
6268
): HttpLogLevel {
6369
val raw = source.get(key) ?: return default
64-
return when (raw.trim().uppercase(Locale.US)) {
65-
"NONE" -> NONE
66-
"HEADERS" -> HEADERS
67-
"BODY_AND_HEADERS" -> BODY_AND_HEADERS
68-
else -> default
69-
}
70+
val name = raw.trim().uppercase(Locale.US)
71+
return entries.firstOrNull { it.name == name } ?: default
7072
}
7173
}
7274
}

sdk-core/src/test/kotlin/org/dexpace/sdk/core/http/pipeline/steps/HttpLogLevelTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ class HttpLogLevelTest {
7777
)
7878
}
7979

80+
@Test
81+
fun `whitespace-only value returns the supplied default`() {
82+
// Configuration only treats an exactly-empty env string as absent, so a whitespace-only
83+
// value is returned as-is; fromEnv's own trim collapses it to "" and falls to the default.
84+
val cfg = configWithEnv("MY_PRODUCT_LOG_LEVEL" to " ")
85+
assertEquals(
86+
HttpLogLevel.HEADERS,
87+
HttpLogLevel.fromEnv("MY_PRODUCT_LOG_LEVEL", cfg, HttpLogLevel.HEADERS),
88+
)
89+
}
90+
8091
// ----- Unrecognized value falls back to the supplied default -----
8192

8293
@Test

0 commit comments

Comments
 (0)