From 3d0e046238cd1a6cf2500e9dffbd581617082535 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 3 Dec 2020 11:33:55 -0700 Subject: caddyauth: Use structured log --- modules/caddyhttp/caddyauth/caddyauth.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/caddyhttp/caddyauth/caddyauth.go b/modules/caddyhttp/caddyauth/caddyauth.go index 3a0a2a0..28b2e1b 100644 --- a/modules/caddyhttp/caddyauth/caddyauth.go +++ b/modules/caddyhttp/caddyauth/caddyauth.go @@ -16,11 +16,11 @@ package caddyauth import ( "fmt" - "log" "net/http" "github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2/modules/caddyhttp" + "go.uber.org/zap" ) func init() { @@ -42,6 +42,8 @@ type Authentication struct { ProvidersRaw caddy.ModuleMap `json:"providers,omitempty" caddy:"namespace=http.authentication.providers"` Providers map[string]Authenticator `json:"-"` + + logger *zap.Logger } // CaddyModule returns the Caddy module information. @@ -54,6 +56,7 @@ func (Authentication) CaddyModule() caddy.ModuleInfo { // Provision sets up a. func (a *Authentication) Provision(ctx caddy.Context) error { + a.logger = ctx.Logger(a) a.Providers = make(map[string]Authenticator) mods, err := ctx.LoadModule(a, "ProvidersRaw") if err != nil { @@ -72,7 +75,9 @@ func (a Authentication) ServeHTTP(w http.ResponseWriter, r *http.Request, next c for provName, prov := range a.Providers { user, authed, err = prov.Authenticate(w, r) if err != nil { - log.Printf("[ERROR] Authenticating with %s: %v", provName, err) + a.logger.Error("auth provider returned error", + zap.String("provider", provName), + zap.Error(err)) continue } if authed { -- cgit v1.2.3