From ac6019137d5b10d02c7acac4f63fa22091b9933d Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Tue, 28 Nov 2017 16:28:48 +0100 Subject: Fix imports for github.com/sirupsen/logrus Change-Id: I84f2e45e5ff188a2a7a80cf69f607b44486c1754 Signed-off-by: Ondrej Fabry --- vendor/github.com/sirupsen/logrus/formatter.go | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 vendor/github.com/sirupsen/logrus/formatter.go (limited to 'vendor/github.com/sirupsen/logrus/formatter.go') diff --git a/vendor/github.com/sirupsen/logrus/formatter.go b/vendor/github.com/sirupsen/logrus/formatter.go new file mode 100644 index 0000000..b5fbe93 --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/formatter.go @@ -0,0 +1,45 @@ +package logrus + +import "time" + +const DefaultTimestampFormat = time.RFC3339 + +// The Formatter interface is used to implement a custom Formatter. It takes an +// `Entry`. It exposes all the fields, including the default ones: +// +// * `entry.Data["msg"]`. The message passed from Info, Warn, Error .. +// * `entry.Data["time"]`. The timestamp. +// * `entry.Data["level"]. The level the entry was logged at. +// +// Any additional fields added with `WithField` or `WithFields` are also in +// `entry.Data`. Format is expected to return an array of bytes which are then +// logged to `logger.Out`. +type Formatter interface { + Format(*Entry) ([]byte, error) +} + +// 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 just silently drop the user provided level. Instead with this code +// it'll logged as: +// +// {"level": "info", "fields.level": 1, "msg": "hello", "time": "..."} +// +// It's not exported because it's still using Data in an opinionated way. It's to +// avoid code duplication between the two default formatters. +func prefixFieldClashes(data Fields) { + if t, ok := data["time"]; ok { + data["fields.time"] = t + } + + if m, ok := data["msg"]; ok { + data["fields.msg"] = m + } + + if l, ok := data["level"]; ok { + data["fields.level"] = l + } +} -- cgit 1.2.3-korg