From 55ad774c8b1a97a4bb3abc5be9c6770e914e1dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hunyadv=C3=A1ri=20P=C3=A9ter?= Date: Thu, 29 Aug 2024 09:46:09 +0200 Subject: [PATCH] fix: setFields create fields if not initielaized --- xlog.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xlog.go b/xlog.go index d75fa4a..ba253dc 100644 --- a/xlog.go +++ b/xlog.go @@ -155,9 +155,7 @@ func New(c Config) Logger { if l.output == nil { l.output = NewOutputChannel(NewConsoleOutput()) } - for k, v := range c.Fields { - l.SetField(k, v) - } + l.SetFields(c.Fields) l.disablePooling = c.DisablePooling l.disableCallerInfo = c.DisableCallerInfo return l @@ -259,6 +257,9 @@ func (l *logger) SetField(name string, value interface{}) { // SetFields func (l *logger) SetFields(fields F) { + if l.fields == nil { + l.fields = map[string]interface{}{} + } for name, value := range fields { l.fields[name] = value }