Skip to content

Commit

Permalink
chore: http errorlog to zap
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Feb 16, 2024
1 parent afe587c commit 69ce610
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 0 additions & 4 deletions internal/server/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"time"
)

func handler(h http.Handler) echo.HandlerFunc {
return echo.WrapHandler(h)
}

func EchoErrorHandler() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
Expand Down
20 changes: 17 additions & 3 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 69ce610

Please sign in to comment.