Skip to content

Commit

Permalink
refactor(http/server): better io.Writer from logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Apr 11, 2022
1 parent fc64bb3 commit c75f265
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 5 additions & 2 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/gin-gonic/gin"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
"go.uber.org/fx"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -56,8 +57,10 @@ func NewServer(
gin.SetMode(gin.ReleaseMode)
}

gin.DefaultWriter = logger
gin.DefaultErrorWriter = logger
writer := zap.NewStdLog(logger.Desugar().Logger).Writer()

gin.DefaultWriter = writer
gin.DefaultErrorWriter = writer

s := Server{
router: gin.Default(),
Expand Down
6 changes: 0 additions & 6 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,3 @@ func New(lc fx.Lifecycle, cfg *config.Config) (*Logger, error) {

return &Logger{otellogger.Sugar()}, nil
}

func (l *Logger) Write(p []byte) (n int, err error) {
l.Debug(string(p))

return len(p), nil
}

0 comments on commit c75f265

Please sign in to comment.