summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-09-08 12:44:58 -0400
committerGitHub <noreply@github.com>2020-09-08 10:44:58 -0600
commit04f50a975932c29bf344b45b3444572b449b1faf (patch)
tree4ccb486c28de3ececaf12a78677223d038550400 /modules/caddyhttp
parent4cd7ae35b3ec3d882168cef669974a2c3aab3618 (diff)
caddyhttp: Wrap http.Server logging with zap (#3668)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/app.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/caddyhttp/app.go b/modules/caddyhttp/app.go
index 40ae3a2..375ca4d 100644
--- a/modules/caddyhttp/app.go
+++ b/modules/caddyhttp/app.go
@@ -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),
@@ -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
@@ -344,6 +351,7 @@ func (app *App) Start() error {
Addr: hostport,
Handler: srv,
TLSConfig: tlsCfg,
+ ErrorLog: serverLogger,
},
}
go h3srv.Serve(h3ln)
@@ -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)
}