diff options
author | Matt Holt <mholt@users.noreply.github.com> | 2019-10-28 14:39:37 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 14:39:37 -0600 |
commit | b00dfd3965f400956c5bb5b388e9d54ef98052e5 (patch) | |
tree | 44517743815327f7ef63405b3a13e54f7f20c885 /admin.go | |
parent | 6c533558a3db4b30a6b7a81d19ac180fe2000ca2 (diff) |
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
Diffstat (limited to 'admin.go')
-rw-r--r-- | admin.go | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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 |