Skip to content

Commit

Permalink
add setFields to set multiple fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Ak-Army committed Jan 22, 2020
1 parent c8258e5 commit fc530de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nop.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var NopLogger = &nop{}

func (n nop) SetField(name string, value interface{}) {}

func (n nop) SetFields(fields F) {}

func (n nop) GetFields() F { return map[string]interface{}{} }

func (n nop) OutputF(level Level, calldepth int, msg string, fields map[string]interface{}, err error) {
Expand Down
10 changes: 10 additions & 0 deletions xlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Logger interface {
// SetField sets a field on the logger's context. All future messages on this logger
// will have this field set.
SetField(name string, value interface{})
// SetFields sets a fielsd on the logger's context. All future messages on this logger
// will have this fields set.
SetFields(fields F)
// GetFields returns all the fields set on the logger
GetFields() F
// Debug logs a debug message. If last parameter is a map[string]string, it's content
Expand Down Expand Up @@ -248,6 +251,13 @@ func (l *logger) SetField(name string, value interface{}) {
l.fields[name] = value
}

// SetFields
func (l *logger) SetFields(fields F) {
for name, value := range fields {
l.fields[name] = value
}
}

// GetFields implements Logger interface
func (l *logger) GetFields() F {
return l.fields
Expand Down

0 comments on commit fc530de

Please sign in to comment.