Repository navigation
Add configurable log_level for the "user authenticated" log line - #116
Merged
Merged
Conversation
Production services typically want to emit a single log line per request rather than one per middleware in the chain. Fix the "user authenticated" message's level at info made that impossible without either duplicate log lines or losing the message. Add a LogLevel field to JWTAuth (defaulting to "info" to preserve existing behavior) and a matching log_level Caddyfile directive, so operators can lower it to "debug" and fold it into a per-request access log instead.
Use zapcore.ParseLevel instead of manually calling UnmarshalText, and logger.Log(level, ...) instead of a hand-rolled dispatch helper -- zap already provides both.
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
LogLevelfield toJWTAuth(JSON keylog_level) and a matchinglog_levelCaddyfile directive, so the level of theuser authenticatedlog line (jwt.go#L483) can be configured instead of being fixed atinfo.debug,info(default, preserves current behavior),warn, orerror. Other zap levels (dpanic,panic,fatal) are explicitly rejected, since using them for a per-request success message would crash or exit the process.Authenticatenow emits the message vialogger.Logwith configured level rather than always callinglogger.Info.Why
Production services typically want to emit a single log line per request rather than one per middleware in the request chain. Because this plugin's "user authenticated" message was hardcoded at
info, operators had no way to fold it into a per-request access/debug log without either duplicating log output atinfoor losing the message entirely. Making the level configurable (e.g.log_level debug) lets it be routed into the same per-request debug output used elsewhere, instead of always producing an extrainfo-level line for every request.Test plan
go build ./...go vet ./...go test ./...(full suite, including the new log-level tests) — all passing