summaryrefslogtreecommitdiff
path: root/modules/caddytls/automation.go
diff options
context:
space:
mode:
authorKévin Dunglas <kevin@dunglas.fr>2024-09-13 19:16:37 +0200
committerGitHub <noreply@github.com>2024-09-13 11:16:37 -0600
commitf4bf4e0097853438eb69c573bbaa0581e9b9c02d (patch)
tree2c01222faa34d3c95072094a2f80c41b1563c19e /modules/caddytls/automation.go
parent21f9c20a04ec5c2ac430daa8e4ba8fbdef67f773 (diff)
perf: use zap's Check() to prevent useless allocs (#6560)
* perf: use zap's Check() to prevent useless allocs * fix * fix * fix * fix * restore previous replacer behavior * fix linter
Diffstat (limited to 'modules/caddytls/automation.go')
-rw-r--r--modules/caddytls/automation.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/modules/caddytls/automation.go b/modules/caddytls/automation.go
index 781818ed..e2e02221 100644
--- a/modules/caddytls/automation.go
+++ b/modules/caddytls/automation.go
@@ -26,6 +26,7 @@ import (
"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/v2"
"go.uber.org/zap"
+ "go.uber.org/zap/zapcore"
"github.com/caddyserver/caddy/v2"
)
@@ -292,21 +293,30 @@ func (ap *AutomationPolicy) Provision(tlsApp *TLS) error {
remoteIP, _, _ = net.SplitHostPort(remote.String())
}
}
- tlsApp.logger.Debug("asking for permission for on-demand certificate",
- zap.String("remote_ip", remoteIP),
- zap.String("domain", name))
+ if c := tlsApp.logger.Check(zapcore.DebugLevel, "asking for permission for on-demand certificate"); c != nil {
+ c.Write(
+ zap.String("remote_ip", remoteIP),
+ zap.String("domain", name),
+ )
+ }
// ask the permission module if this cert is allowed
if err := tlsApp.Automation.OnDemand.permission.CertificateAllowed(ctx, name); err != nil {
// distinguish true errors from denials, because it's important to elevate actual errors
if errors.Is(err, ErrPermissionDenied) {
- tlsApp.logger.Debug("on-demand certificate issuance denied",
- zap.String("domain", name),
- zap.Error(err))
+ if c := tlsApp.logger.Check(zapcore.DebugLevel, "on-demand certificate issuance denied"); c != nil {
+ c.Write(
+ zap.String("domain", name),
+ zap.Error(err),
+ )
+ }
} else {
- tlsApp.logger.Error("failed to get permission for on-demand certificate",
- zap.String("domain", name),
- zap.Error(err))
+ if c := tlsApp.logger.Check(zapcore.ErrorLevel, "failed to get permission for on-demand certificate"); c != nil {
+ c.Write(
+ zap.String("domain", name),
+ zap.Error(err),
+ )
+ }
}
return err
}