mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
caddyauth: Use structured log
This commit is contained in:
parent
bac82073d0
commit
3d0e046238
1 changed files with 7 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue