Skip to content

Commit

Permalink
refactor(logger): add Writer method
Browse files Browse the repository at this point in the history
  • Loading branch information
mgjules committed Apr 11, 2022
1 parent c75f265 commit b228da3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 3 additions & 5 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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 @@ -57,10 +56,9 @@ func NewServer(
gin.SetMode(gin.ReleaseMode)
}

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

gin.DefaultWriter = writer
gin.DefaultErrorWriter = writer
w := logger.Writer()
gin.DefaultWriter = w
gin.DefaultErrorWriter = w

s := Server{
router: gin.Default(),
Expand Down
6 changes: 6 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logger
import (
"context"
"fmt"
"io"

"github.com/JulesMike/spoty/config"
"github.com/uptrace/opentelemetry-go-extra/otelzap"
Expand Down Expand Up @@ -46,3 +47,8 @@ func New(lc fx.Lifecycle, cfg *config.Config) (*Logger, error) {

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

// Writer returns the logger's io.Writer.
func (l *Logger) Writer() io.Writer {
return zap.NewStdLog(l.Desugar().Logger).Writer()
}

0 comments on commit b228da3

Please sign in to comment.