chore: http errorlog to zap

This commit is contained in:
Johan Siebens
2024-02-16 09:19:48 +01:00
parent afe587cb03
commit 69ce610579
2 changed files with 17 additions and 7 deletions
+17 -3
View File
@@ -193,11 +193,11 @@ func Start(ctx context.Context, c *config.Config) error {
http2Server := &http2.Server{}
g := new(errgroup.Group)
g.Go(func() error { return http.Serve(httpL, h2c.NewHandler(tlsAppHandler, http2Server)) })
g.Go(func() error { return http.Serve(metricsL, metricsHandler) })
g.Go(func() error { return httpServe(httpLogger, httpL, h2c.NewHandler(tlsAppHandler, http2Server)) })
g.Go(func() error { return httpServe(httpLogger, metricsL, metricsHandler) })
if tlsL != nil {
g.Go(func() error { return http.Serve(nonTlsL, nonTlsAppHandler) })
g.Go(func() error { return httpServe(httpLogger, nonTlsL, nonTlsAppHandler) })
}
if c.Tls.AcmeEnabled {
@@ -277,6 +277,20 @@ func selectListener(a net.Listener, b net.Listener) net.Listener {
return b
}
func httpServe(logger *zap.Logger, l net.Listener, handler http.Handler) error {
errorLog, err := zap.NewStdLogAt(logger, zap.DebugLevel)
if err != nil {
return err
}
s := &http.Server{
Handler: handler,
ErrorLog: errorLog,
}
return s.Serve(l)
}
func setupLogging(config config.Logging) (*zap.Logger, error) {
level, err := zap.ParseAtomicLevel(config.Level)
if err != nil {