diff --git a/logger/fields.go b/logger/fields.go index bd4eb68..41e0059 100644 --- a/logger/fields.go +++ b/logger/fields.go @@ -35,16 +35,16 @@ func NewFields() Fields { return make(Fields) } -func (f Fields) new() map[string]interface{} { - return make(map[string]interface{}, 0) -} - func (f Fields) clone() map[string]interface{} { + res := make(map[string]interface{}, 0) + if len(f) > 0 { - return f + for k, v := range f { + res[k] = v + } } - return f.new() + return res } func (f Fields) Add(key string, val interface{}) Fields { @@ -84,7 +84,7 @@ func (f Fields) Merge(other Fields) Fields { } func (f Fields) Clean(keys ...string) Fields { - res := f.new() + res := make(map[string]interface{}, 0) if len(keys) > 0 { f.Map(func(key string, val interface{}) interface{} { diff --git a/logger/interface.go b/logger/interface.go index 17ada6d..8dfe929 100644 --- a/logger/interface.go +++ b/logger/interface.go @@ -125,7 +125,7 @@ func New() Logger { lvl.Store(InfoLevel) return &logger{ - m: sync.Mutex{}, + m: &sync.Mutex{}, l: lvl, o: new(atomic.Value), s: new(atomic.Value), diff --git a/logger/model.go b/logger/model.go index dab7809..3d01104 100644 --- a/logger/model.go +++ b/logger/model.go @@ -55,7 +55,7 @@ var _selfPackage = path.Base(reflect.TypeOf(logger{}).PkgPath()) type logger struct { x context.Context n context.CancelFunc - m sync.Mutex + m sync.Locker l *atomic.Value //current level set for this logger o *atomic.Value //options s *atomic.Value //logrus logger @@ -144,7 +144,7 @@ func (l *logger) Clone(ctx context.Context) (Logger, error) { c := &logger{ x: nil, n: nil, - m: sync.Mutex{}, + m: &sync.Mutex{}, l: new(atomic.Value), o: new(atomic.Value), s: new(atomic.Value),