@marcel91200 / caddy Mirror · read-only / commits / 04f50a97
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

caddyhttp: Wrap http.Server logging with zap (#3668)

Francis Lavoie committed Sep 8, 2020 at 12:44 UTC 04f50a975932c29bf344b45b3444572b449b1faf
1 file changed +9 -1
modules/caddyhttp/app.go
+9 -1
@@ -281,6 +281,12 @@ func (app *App) Validate() error {
281 // Start runs the app. It finishes automatic HTTPS if enabled,
282 // including management of certificates.
283 func (app *App) Start() error {
284 + // get a logger compatible with http.Server
285 + serverLogger, err := zap.NewStdLogAt(app.logger.Named("stdlib"), zap.DebugLevel)
286 + if err != nil {
287 + return fmt.Errorf("failed to set up server logger: %v", err)
288 + }
289 +
290 for srvName, srv := range app.Servers {
291 s := &http.Server{
292 ReadTimeout: time.Duration(srv.ReadTimeout),
@@ -289,6 +295,7 @@ func (app *App) Start() error {
295 IdleTimeout: time.Duration(srv.IdleTimeout),
296 MaxHeaderBytes: srv.MaxHeaderBytes,
297 Handler: srv,
298 + ErrorLog: serverLogger,
299 }
300
301 // enable h2c if configured
@@ -344,6 +351,7 @@ func (app *App) Start() error {
351 Addr: hostport,
352 Handler: srv,
353 TLSConfig: tlsCfg,
354 + ErrorLog: serverLogger,
355 },
356 }
357 go h3srv.Serve(h3ln)
@@ -382,7 +390,7 @@ func (app *App) Start() error {
390
391 // finish automatic HTTPS by finally beginning
392 // certificate management
385 - err := app.automaticHTTPSPhase2()
393 + err = app.automaticHTTPSPhase2()
394 if err != nil {
395 return fmt.Errorf("finalizing automatic HTTPS: %v", err)
396 }