mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-15 21:28:38 +00:00
72ac04e7ca
With: $ git mv vendor/github.com/{S,s}irupsen $ sed -i 's/Sirupsen/sirupsen/g' $(git grep -l Sirupsen) catching up with the upstream lowercasing [1,2,3,4]. Because of the compatibility issues discussed in [3], some consumers may prefer to use the old uppercase version until they have time to update their other Logrus consumers to the new lowercase form. [1]: https://github.com/sirupsen/logrus/blame/v1.0.3/README.md#L6 [2]: https://github.com/sirupsen/logrus/pull/384 [3]: https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276 [4]: https://github.com/sirupsen/logrus/issues/553
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
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
|
|
}
|
|
}
|