Skip to content

Commit 69ce610

Browse files
committed
chore: http errorlog to zap
1 parent afe587c commit 69ce610

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

internal/server/echo.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
"time"
1010
)
1111

12-
func handler(h http.Handler) echo.HandlerFunc {
13-
return echo.WrapHandler(h)
14-
}
15-
1612
func EchoErrorHandler() echo.MiddlewareFunc {
1713
return func(next echo.HandlerFunc) echo.HandlerFunc {
1814
return func(c echo.Context) error {

internal/server/server.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ func Start(ctx context.Context, c *config.Config) error {
193193
http2Server := &http2.Server{}
194194
g := new(errgroup.Group)
195195

196-
g.Go(func() error { return http.Serve(httpL, h2c.NewHandler(tlsAppHandler, http2Server)) })
197-
g.Go(func() error { return http.Serve(metricsL, metricsHandler) })
196+
g.Go(func() error { return httpServe(httpLogger, httpL, h2c.NewHandler(tlsAppHandler, http2Server)) })
197+
g.Go(func() error { return httpServe(httpLogger, metricsL, metricsHandler) })
198198

199199
if tlsL != nil {
200-
g.Go(func() error { return http.Serve(nonTlsL, nonTlsAppHandler) })
200+
g.Go(func() error { return httpServe(httpLogger, nonTlsL, nonTlsAppHandler) })
201201
}
202202

203203
if c.Tls.AcmeEnabled {
@@ -277,6 +277,20 @@ func selectListener(a net.Listener, b net.Listener) net.Listener {
277277
return b
278278
}
279279

280+
func httpServe(logger *zap.Logger, l net.Listener, handler http.Handler) error {
281+
errorLog, err := zap.NewStdLogAt(logger, zap.DebugLevel)
282+
if err != nil {
283+
return err
284+
}
285+
286+
s := &http.Server{
287+
Handler: handler,
288+
ErrorLog: errorLog,
289+
}
290+
291+
return s.Serve(l)
292+
}
293+
280294
func setupLogging(config config.Logging) (*zap.Logger, error) {
281295
level, err := zap.ParseAtomicLevel(config.Level)
282296
if err != nil {

0 commit comments

Comments
 (0)