Skip to content

Commit

Permalink
Fixing review findings 4
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Nikolic <[email protected]>
  • Loading branch information
duricanikolic committed Aug 16, 2023
1 parent 1965c0c commit 3d505b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions log/gokit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
)

const (
Expand All @@ -32,6 +33,14 @@ func NewGoKit(format string, writer io.Writer) log.Logger {
return log.NewLogfmtLogger(writer)
}

// NewGoKitWithLevel creates a new GoKit logger with the given level, format and writer.
// If the given writer is nil, os.Stderr is used.
// If the given format is nil, logfmt is used.
func NewGoKitWithLevel(lvl Level, format string, writer io.Writer) log.Logger {
logger := NewGoKit(format, writer)
return level.NewFilter(logger, lvl.Option)
}

// stand-alone for test purposes
func addStandardFields(logger log.Logger) log.Logger {
return log.With(logger, "ts", log.DefaultTimestampUTC, "caller", log.Caller(5))
Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ func newServer(cfg Config, metrics *Metrics) (*Server, error) {
// If user doesn't supply a logging implementation, by default instantiate go-kit.
logger := cfg.Log
if logger == nil {
logger = log.NewGoKit(log.LogfmtFormat, os.Stderr)
writer := gokit_log.NewSyncWriter(os.Stderr)
logger = log.NewGoKitWithLevel(cfg.LogLevel, cfg.LogFormat, writer)
}

gatherer := cfg.Gatherer
Expand Down

0 comments on commit 3d505b9

Please sign in to comment.