From b00dfd3965f400956c5bb5b388e9d54ef98052e5 Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Mon, 28 Oct 2019 14:39:37 -0600 Subject: v2: Logging! (#2831) * logging: Initial implementation * logging: More encoder formats, better defaults * logging: Fix repetition bug with FilterEncoder; add more presets * logging: DiscardWriter; delete or no-op logs that discard their output * logging: Add http.handlers.log module; enhance Replacer methods The Replacer interface has new methods to customize how to handle empty or unrecognized placeholders. Closes #2815. * logging: Overhaul HTTP logging, fix bugs, improve filtering, etc. * logging: General cleanup, begin transitioning to using new loggers * Fixes after merge conflict --- admin.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'admin.go') diff --git a/admin.go b/admin.go index db8b700..0b4affd 100644 --- a/admin.go +++ b/admin.go @@ -34,6 +34,7 @@ import ( "github.com/caddyserver/caddy/v2/caddyconfig" "github.com/mholt/certmagic" "github.com/rs/cors" + "go.uber.org/zap" ) var ( @@ -52,6 +53,8 @@ var DefaultAdminConfig = &AdminConfig{ Listen: DefaultAdminListen, } +// TODO: holy smokes, the admin endpoint might not have to live in caddy's core. + // StartAdmin starts Caddy's administration endpoint, // bootstrapping it with an optional configuration // in the format of JSON bytes. It opens a listener @@ -113,7 +116,15 @@ func StartAdmin(initialConfigJSON []byte) error { } } - handler := cors.Default().Handler(mux) + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // TODO: improve/organize this logging + Log().Named("admin.request").Info("", + zap.String("method", r.Method), + zap.String("uri", r.RequestURI), + zap.String("remote", r.RemoteAddr), + ) + cors.Default().Handler(mux).ServeHTTP(w, r) + }) cfgEndptSrv = &http.Server{ Handler: handler, @@ -125,14 +136,14 @@ func StartAdmin(initialConfigJSON []byte) error { go cfgEndptSrv.Serve(ln) - log.Println("Caddy 2 admin endpoint listening on", adminConfig.Listen) + fmt.Println("Caddy 2 admin endpoint listening on", adminConfig.Listen) if len(initialConfigJSON) > 0 { err := Load(bytes.NewReader(initialConfigJSON)) if err != nil { return fmt.Errorf("loading initial config: %v", err) } - log.Println("Caddy 2 serving initial configuration") + fmt.Println("Caddy 2 serving initial configuration") } return nil -- cgit v1.2.3