MCPcopy Create free account
hub / github.com/ddev/ddev / prefixFieldClashes

Function prefixFieldClashes

pkg/output/text_formatter.go:199–211  ·  view source on GitHub ↗

This is to not silently overwrite `time`, `msg` and `level` fields when dumping it. If this code wasn't there doing: logrus.WithField("level", 1).Info("hello") Would silently drop the user provided level. Instead with this code it'll logged as: {"level": "info", "fields.level": 1, "msg": "hello

(data log.Fields)

Source from the content-addressed store, hash-verified

197// It's not exported because it's still using Data in an opinionated way. It's to
198// avoid code duplication between the two default formatters.
199func prefixFieldClashes(data log.Fields) {
200 if t, ok := data["time"]; ok {
201 data["fields.time"] = t
202 }
203
204 if m, ok := data["msg"]; ok {
205 data["fields.msg"] = m
206 }
207
208 if level, ok := data["level"]; ok {
209 data["fields.level"] = level
210 }
211}

Callers 1

FormatMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected