logrus icon indicating copy to clipboard operation
logrus copied to clipboard

Fix func and file field clash (duplicated fields)

Open pgillich opened this issue 5 years ago • 0 comments

In case of:

  • ReportCaller=true
  • func and/or file fields are clased (set by WithField() or WithFields())

The TextFormatter duplicates the clashed func and/or file fields.

Root cause: prefixFieldClashes() does not delete func and/or file fields, if it are renamed to fileds.func and/or fields.file. The TextFormatter.Format() merges keys and fixedKeys, so func and file are duplicated in the merged slice, because TextFormatter.Format() does not use unique list.

TestJSONFieldClashWithCaller didn't detect this problem, because it uses unique data model (map instead of slice)

Solution:

  • deleting func and/or file fields in prefixFieldClashes(), if it are renamed.
  • new unit tests

pgillich avatar Dec 29 '19 22:12 pgillich