mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-23 00:56:45 +01:00
caddyhttp: Wrap http.Server logging with zap (#3668)
This commit is contained in:
parent
4cd7ae35b3
commit
04f50a9759
1 changed files with 9 additions and 1 deletions
|
@ -281,6 +281,12 @@ func (app *App) Validate() error {
|
||||||
// Start runs the app. It finishes automatic HTTPS if enabled,
|
// Start runs the app. It finishes automatic HTTPS if enabled,
|
||||||
// including management of certificates.
|
// including management of certificates.
|
||||||
func (app *App) Start() error {
|
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 {
|
for srvName, srv := range app.Servers {
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
ReadTimeout: time.Duration(srv.ReadTimeout),
|
ReadTimeout: time.Duration(srv.ReadTimeout),
|
||||||
|
@ -289,6 +295,7 @@ func (app *App) Start() error {
|
||||||
IdleTimeout: time.Duration(srv.IdleTimeout),
|
IdleTimeout: time.Duration(srv.IdleTimeout),
|
||||||
MaxHeaderBytes: srv.MaxHeaderBytes,
|
MaxHeaderBytes: srv.MaxHeaderBytes,
|
||||||
Handler: srv,
|
Handler: srv,
|
||||||
|
ErrorLog: serverLogger,
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable h2c if configured
|
// enable h2c if configured
|
||||||
|
@ -344,6 +351,7 @@ func (app *App) Start() error {
|
||||||
Addr: hostport,
|
Addr: hostport,
|
||||||
Handler: srv,
|
Handler: srv,
|
||||||
TLSConfig: tlsCfg,
|
TLSConfig: tlsCfg,
|
||||||
|
ErrorLog: serverLogger,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
go h3srv.Serve(h3ln)
|
go h3srv.Serve(h3ln)
|
||||||
|
@ -382,7 +390,7 @@ func (app *App) Start() error {
|
||||||
|
|
||||||
// finish automatic HTTPS by finally beginning
|
// finish automatic HTTPS by finally beginning
|
||||||
// certificate management
|
// certificate management
|
||||||
err := app.automaticHTTPSPhase2()
|
err = app.automaticHTTPSPhase2()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("finalizing automatic HTTPS: %v", err)
|
return fmt.Errorf("finalizing automatic HTTPS: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue