Skip to content

Commit

Permalink
caddyhttp: Wrap http.Server logging with zap (#3668)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Sep 8, 2020
1 parent 4cd7ae3 commit 04f50a9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/caddyhttp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ func (app *App) Validate() error {
// Start runs the app. It finishes automatic HTTPS if enabled,
// including management of certificates.
func (app *App) Start() error {
// get a logger compatible with http.Server
serverLogger, err := zap.NewStdLogAt(app.logger.Named("stdlib"), zap.DebugLevel)
if err != nil {
return fmt.Errorf("failed to set up server logger: %v", err)
}

for srvName, srv := range app.Servers {
s := &http.Server{
ReadTimeout: time.Duration(srv.ReadTimeout),
Expand All @@ -289,6 +295,7 @@ func (app *App) Start() error {
IdleTimeout: time.Duration(srv.IdleTimeout),
MaxHeaderBytes: srv.MaxHeaderBytes,
Handler: srv,
ErrorLog: serverLogger,
}

// enable h2c if configured
Expand Down Expand Up @@ -344,6 +351,7 @@ func (app *App) Start() error {
Addr: hostport,
Handler: srv,
TLSConfig: tlsCfg,
ErrorLog: serverLogger,
},
}
go h3srv.Serve(h3ln)
Expand Down Expand Up @@ -382,7 +390,7 @@ func (app *App) Start() error {

// finish automatic HTTPS by finally beginning
// certificate management
err := app.automaticHTTPSPhase2()
err = app.automaticHTTPSPhase2()
if err != nil {
return fmt.Errorf("finalizing automatic HTTPS: %v", err)
}
Expand Down

0 comments on commit 04f50a9

Please sign in to comment.