smallstep / certificates

🛡️ A private certificate authority (X.509 & SSH) & ACME server for secure automated certificate management, so you can use TLS everywhere & SSO for SSH.
https://smallstep.com/certificates
Apache License 2.0
6.36k stars 415 forks source link

Log errors using slog.Logger #1849

Closed maraino closed 1 month ago

maraino commented 1 month ago

This commit allows logging errors in a slog.Logger injected in the context. This logger type is not currently used directly in step-ca, but this will change in the future.

The main change is in api/log/log.go; the rest is adapting the code to allow this.

I've considered using func Error(ctx context.Context, w http.ResponseWriter, err error), but this won't allow us to add extra things from the request to the log if we need to.

I've also had to change the render methods because they can call Error.

cc: @hslatman