Skip to content

Commit 117d663

Browse files
author
Amanbolat Balabekov
authored
fix: remove recreating zap logger; change time field to latency (brpaz#2)
1 parent 794c1c9 commit 117d663

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

logger.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func ZapLogger(log *zap.Logger) echo.MiddlewareFunc {
1717

1818
err := next(c)
1919
if err != nil {
20-
log = log.With(zap.Error(err))
2120
c.Error(err)
2221
}
2322

@@ -26,7 +25,7 @@ func ZapLogger(log *zap.Logger) echo.MiddlewareFunc {
2625

2726
fields := []zapcore.Field{
2827
zap.String("remote_ip", c.RealIP()),
29-
zap.String("time", time.Since(start).String()),
28+
zap.String("latency", time.Since(start).String()),
3029
zap.String("host", req.Host),
3130
zap.String("request", fmt.Sprintf("%s %s", req.Method, req.RequestURI)),
3231
zap.Int("status", res.Status),
@@ -43,9 +42,9 @@ func ZapLogger(log *zap.Logger) echo.MiddlewareFunc {
4342
n := res.Status
4443
switch {
4544
case n >= 500:
46-
log.Error("Server error", fields...)
45+
log.With(zap.Error(err)).Error("Server error", fields...)
4746
case n >= 400:
48-
log.Warn("Client error", fields...)
47+
log.With(zap.Error(err)).Warn("Client error", fields...)
4948
case n >= 300:
5049
log.Info("Redirection", fields...)
5150
default:

0 commit comments

Comments
 (0)