fix: log klog, gRPC and stdlib output as JSON #59

Merged
rcsheets merged 1 commit from fix/klog-json-logging into main 2026-10-27 21:27:55 +00:00
Owner

The controller logs mostly JSON, but client-go's leader election writes plain klog lines in between:

I1027 21:20:20.104628       1 leaderelection.go:254] attempting to acquire leader lease forgejo-runner-system/forgejo-runner-operator.brooktrails.org...
I1027 21:20:48.482285       1 leaderelection.go:268] successfully acquired lease forgejo-runner-system/forgejo-runner-operator.brooktrails.org

controller-runtime's zap logger only covers code that logs through ctrl.Log. Three dependencies of both binaries keep their own loggers and default to plain text:

Source Used by
klog client-go (leader election, informers)
grpclog gRPC (controller remote backend, provisioner server)
stdlib log net/http server errors, e.g. failed TLS handshakes on the webhook/metrics servers

internal/logging.Setup builds the zap logger once and installs it for all four; the controller and provisioner call it in place of ctrl.SetLogger. gRPC is held at error level, matching grpclog's default severity, so info-level connectivity chatter does not start appearing. klog, gRPC and stdlib lines carry logger names klog, grpc and stdlog.

zapr, zap and klog/v2 move from indirect to direct requirements; no versions change.

Testing: internal/logging has a test that emits through each source and asserts every line parses as JSON and gRPC info is filtered. make build and make test pass.

🤖 Generated with Claude Code

The controller logs mostly JSON, but client-go's leader election writes plain klog lines in between: ``` I1027 21:20:20.104628 1 leaderelection.go:254] attempting to acquire leader lease forgejo-runner-system/forgejo-runner-operator.brooktrails.org... I1027 21:20:48.482285 1 leaderelection.go:268] successfully acquired lease forgejo-runner-system/forgejo-runner-operator.brooktrails.org ``` controller-runtime's zap logger only covers code that logs through `ctrl.Log`. Three dependencies of both binaries keep their own loggers and default to plain text: | Source | Used by | |---|---| | klog | client-go (leader election, informers) | | grpclog | gRPC (controller remote backend, provisioner server) | | stdlib `log` | `net/http` server errors, e.g. failed TLS handshakes on the webhook/metrics servers | `internal/logging.Setup` builds the zap logger once and installs it for all four; the controller and provisioner call it in place of `ctrl.SetLogger`. gRPC is held at error level, matching grpclog's default severity, so info-level connectivity chatter does not start appearing. klog, gRPC and stdlib lines carry `logger` names `klog`, `grpc` and `stdlog`. `zapr`, `zap` and `klog/v2` move from indirect to direct requirements; no versions change. Testing: `internal/logging` has a test that emits through each source and asserts every line parses as JSON and gRPC info is filtered. `make build` and `make test` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix: log klog, gRPC and stdlib output as JSON
Some checks failed
CI (next Go) / next-go (tip) (pull_request) Successful in 2m44s
CI / ci (pull_request) Successful in 1m49s
E2E smoke test / e2e (pull_request) Failing after 2s
028ee92542
The controller logged mostly JSON, but client-go's leader election
wrote plain klog lines in between:

  I1027 21:20:20.104628 1 leaderelection.go:254] attempting to acquire leader lease ...

controller-runtime's zap logger only covers code that logs through
ctrl.Log. Three dependencies keep their own loggers and default to
plain text: klog (client-go), grpclog (gRPC) and the standard library's
log package (net/http server errors such as failed TLS handshakes).

A new internal/logging.Setup builds the zap logger once and installs it
for all four. Both the controller and the provisioner call it in place
of ctrl.SetLogger. gRPC is held at error level, matching grpclog's
default severity, so its info-level connectivity chatter stays out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator

Automated review by pr-reviewer v0.54.0 | Safety Check | Nemotron 3 Nano | tracking id r-e1169d-981e41
This is an AI-generated review and may contain mistakes.

Status: ❌ Failed


Review failed. Tracking id r-e1169d-981e41 — see logs for details.

Comment @pr-reviewer-bot retry to try again.

<!-- pr-reviewer:review --> *Automated review by [pr-reviewer](https://git.brooktrails.org/brooktrails/pr-reviewer) v0.54.0 | Safety Check | Nemotron 3 Nano | tracking id `r-e1169d-981e41`* *This is an AI-generated review and may contain mistakes.* **Status:** ❌ Failed --- Review failed. Tracking id `r-e1169d-981e41` — see logs for details. Comment `@pr-reviewer-bot retry` to try again.
rcsheets deleted branch fix/klog-json-logging 2026-10-27 21:27:57 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
brooktrails/forgejo-runner-operator!59
No description provided.