Skip to content

feat: add HttpLogLevel.fromEnv with a caller-supplied key and source#95

Merged
OmarAlJarrah merged 3 commits into
mainfrom
feat/loglevel-from-env
Jun 16, 2026
Merged

feat: add HttpLogLevel.fromEnv with a caller-supplied key and source#95
OmarAlJarrah merged 3 commits into
mainfrom
feat/loglevel-from-env

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Adds a factory for resolving the HTTP log level from an environment variable:

@JvmStatic @JvmOverloads
public fun fromEnv(key: String, source: Configuration, default: HttpLogLevel = NONE): HttpLogLevel

The caller supplies both the variable key and the source — the existing Configuration env-source seam, whose lookup is injectable — so no key is baked into core and tests resolve against a fake source without touching the real environment. Parsing is case-insensitive and trims surrounding whitespace; an unset key or unrecognized value falls back to the supplied default (itself defaulting to NONE).

New tests inject a fake source and cover known/case-insensitive/whitespace/unset/unrecognized resolution. The factory is added to the API snapshot.

Closes #46

Add HttpLogLevel.fromEnv(key, source, default) so a log level can be
driven from an environment variable without the toolkit baking in a
variable name. The caller supplies both the key (e.g. a generated
client passes its own product's variable) and the source, reusing the
existing Configuration env-source seam so the lookup is injectable and
tests never touch the real process environment.

Parsing is tolerant: values match the enum names case-insensitively and
after trimming surrounding whitespace. An unset key, an empty value
(which Configuration treats as absent), or an unrecognized value falls
back to the supplied default, which itself defaults to NONE so logging
stays off unless explicitly opted into.
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.
…he non-env layers

The factory resolves through the full Configuration layering (override ->
env -> system property), not just the environment, so fromEnv was a
misnomer that the KDoc had to walk back. Rename it to fromConfiguration to
match the existing ProxyOptions.fromConfiguration(Configuration) factory
and tighten the doc accordingly.

Add tests covering resolution from the system-property layer and an
explicit override winning over a conflicting env value, which the prior
env-only suite never exercised despite the documented layering.
@OmarAlJarrah OmarAlJarrah merged commit 96f02d5 into main Jun 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpLogLevel.fromEnv with a caller-supplied key and source

1 participant