Skip to content

Commit

Permalink
added variadic fields to log creation
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Avramenko <[email protected]>
  • Loading branch information
Mixaster995 committed Dec 3, 2021
1 parent 206497a commit f4b93f6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/tools/log/logruslogger/logruslogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,25 @@ func (s *logrusLogger) WithField(key, value interface{}) log.Logger {
return logger
}

// Field is simple key value pair
type Field struct {
key string
val interface{}
}

func toMap(fields ...Field) map[string]interface{} {
rv := make(map[string]interface{})

for _, f := range fields {
rv[f.key] = f.val
}

return rv
}

// New - creates a logruslogger and returns it
func New(ctx context.Context) log.Logger {
entry := logrus.NewEntry(logrus.StandardLogger())
func New(ctx context.Context, fields ...Field) log.Logger {
entry := logrus.WithFields(toMap(fields...))
entry.Logger.SetFormatter(newFormatter())

newLog := &logrusLogger{
Expand Down

0 comments on commit f4b93f6

Please sign in to comment.