Skip to content

Add configurable log_level for the "user authenticated" log line - #116

Merged
ggicci merged 3 commits into
ggicci:mainfrom
ddl-ebrown:configurable-log-level
Aug 21, 2026
Merged

ggicci merged 3 commits into
ggicci:mainfrom
ddl-ebrown:configurable-log-level

Conversation

@ddl-ebrown

@ddl-ebrown ddl-ebrown commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a LogLevel field to JWTAuth (JSON key log_level) and a matching log_level Caddyfile directive, so the level of the user authenticated log line (jwt.go#L483) can be configured instead of being fixed at info.
  • Accepts debug, info (default, preserves current behavior), warn, or error. Other zap levels (dpanic, panic, fatal) are explicitly rejected, since using them for a per-request success message would crash or exit the process.
  • Authenticate now emits the message vialogger.Log with configured level rather than always calling logger.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 at info or 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 extra info-level line for every request.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./... (full suite, including the new log-level tests) — all passing

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.
@ggicci
ggicci merged commit f90e611 into ggicci:main Aug 21, 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.

2 participants