1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

caddyauth: Use structured log

This commit is contained in:
Matthew Holt 2020-12-03 11:33:55 -07:00
parent bac82073d0
commit 3d0e046238
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -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 {