diff --git a/internal/api/web/middleware/log/adapter.go b/internal/api/web/middleware/log/adapter.go index 31e6313..74cea14 100644 --- a/internal/api/web/middleware/log/adapter.go +++ b/internal/api/web/middleware/log/adapter.go @@ -2,6 +2,7 @@ package log import ( "io" + "strings" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -13,25 +14,67 @@ type writerLogger struct { } func AsWriter(log *zap.SugaredLogger, level zapcore.Level) io.Writer { - return &writerLogger{log: log} + return &writerLogger{log: log, level: level} } func (w *writerLogger) Write(p []byte) (n int, err error) { switch w.level { case zapcore.DebugLevel: - w.log.Debug(string(p)) + for _, line := range strings.Split(string(p), "\n") { + line = strings.TrimSpace(line) + if line == "" { + return + } + w.log.Debug(line) + } case zapcore.InfoLevel: - w.log.Info(string(p)) + for _, line := range strings.Split(string(p), "\n") { + line = strings.TrimSpace(line) + if line == "" { + return + } + w.log.Info(line) + } case zapcore.WarnLevel: - w.log.Warn(string(p)) + for _, line := range strings.Split(string(p), "\n") { + line = strings.TrimSpace(line) + if line == "" { + return + } + w.log.Warn(line) + } case zapcore.ErrorLevel: - w.log.Error(string(p)) + for _, line := range strings.Split(string(p), "\n") { + line = strings.TrimSpace(line) + if line == "" { + return + } + w.log.Error(line) + } case zapcore.DPanicLevel: - w.log.DPanic(string(p)) + for _, line := range strings.Split(string(p), "\n") { + line = strings.TrimSpace(line) + if line == "" { + return + } + w.log.DPanic(line) + } case zapcore.PanicLevel: - w.log.Panic(string(p)) + for _, line := range strings.Split(string(p), "\n") { + line = strings.TrimSpace(line) + if line == "" { + return + } + w.log.Panic(line) + } case zapcore.FatalLevel: - w.log.Fatal(string(p)) + for _, line := range strings.Split(string(p), "\n") { + line = strings.TrimSpace(line) + if line == "" { + return + } + w.log.Fatal(line) + } } return len(p), nil }