feat: add HttpLogLevel.fromEnv with a caller-supplied key and source#95
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a factory for resolving the HTTP log level from an environment variable:
The caller supplies both the variable
keyand thesource— the existingConfigurationenv-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 supplieddefault(itself defaulting toNONE).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