diff --git a/log/logger.go b/log/logger.go index d59ef008..01f7ea9b 100755 --- a/log/logger.go +++ b/log/logger.go @@ -76,8 +76,18 @@ func NewLoggerWithField(key string, value interface{}) Logger { if logger == nil { InitLogger("debug", "") // nolint: errcheck, gosec // err will always be nil in this case. } - l := logger.WithField(key, value) - return l + return logger.WithField(key, value) +} + +// NewDerivedLoggerWithField returns a logger that inherits all properties of the parent logger, +// and add the given fields for each log entry. +// +// Panics if parent logger is nil. +func NewDerivedLoggerWithField(parentLogger Logger, key string, value interface{}) Logger { + if parentLogger == nil { + panic("parent logger should not be nil") + } + return parentLogger.WithField(key, value) } // customTextFormatter is defined to override default formating options for log entry. diff --git a/session/session.go b/session/session.go index bd54db72..463c2357 100644 --- a/session/session.go +++ b/session/session.go @@ -394,9 +394,8 @@ func makeAllocation(balInfo perun.BalInfo, chAsset pchannel.Asset) (*pchannel.Al // addCh adds the channel to session. It locks the session mutex during the operation. func (s *session) addCh(ch *channel) { - ch.Logger = log.NewLoggerWithField("channel-id", ch.id) + ch.Logger = log.NewDerivedLoggerWithField(s.Logger, "channel-id", ch.id) s.Lock() - // TODO: (mano) use logger with multiple fields and use session-id, channel-id. s.chs[ch.id] = ch s.Unlock() }