clone zap on fields
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
f2ca0bc9d9
commit
a78e1e86cb
29
zap.go
29
zap.go
@ -78,21 +78,32 @@ func (l *zaplog) Init(opts ...logger.Option) error {
|
|||||||
|
|
||||||
func (l *zaplog) Fields(fields map[string]interface{}) logger.Logger {
|
func (l *zaplog) Fields(fields map[string]interface{}) logger.Logger {
|
||||||
l.Lock()
|
l.Lock()
|
||||||
l.fields = make(map[string]interface{}, len(fields))
|
nfields := make(map[string]interface{}, len(l.fields))
|
||||||
for k, v := range fields {
|
for k, v := range l.fields {
|
||||||
l.fields[k] = v
|
nfields[k] = v
|
||||||
}
|
}
|
||||||
l.Unlock()
|
l.Unlock()
|
||||||
|
for k, v := range fields {
|
||||||
|
nfields[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
return l
|
data := make([]zap.Field, 0, len(nfields))
|
||||||
|
for k, v := range fields {
|
||||||
|
data = append(data, zap.Any(k, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
zl := &zaplog{
|
||||||
|
cfg: l.cfg,
|
||||||
|
zap: l.zap.With(data...),
|
||||||
|
opts: l.opts,
|
||||||
|
fields: make(map[string]interface{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
return zl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zaplog) Error(err error) logger.Logger {
|
func (l *zaplog) Error(err error) logger.Logger {
|
||||||
l.Lock()
|
return l.Fields(map[string]interface{}{"error": err})
|
||||||
l.fields["error"] = err
|
|
||||||
l.Unlock()
|
|
||||||
|
|
||||||
return l
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zaplog) Log(level logger.Level, args ...interface{}) {
|
func (l *zaplog) Log(level logger.Level, args ...interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user