mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 23:56:24 -04:00
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.9.4 to 1.10.2. - [Release notes](https://github.com/sirupsen/logrus/releases) - [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md) - [Commits](https://github.com/sirupsen/logrus/compare/v1.9.4...v1.10.2) --- updated-dependencies: - dependency-name: github.com/sirupsen/logrus dependency-version: 1.10.2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
92 lines
2.8 KiB
Go
92 lines
2.8 KiB
Go
package logrus
|
|
|
|
import "time"
|
|
|
|
const (
|
|
// defaultTimestampFormat is the layout used to format entry timestamps
|
|
// when a formatter has not specified a custom TimestampFormat.
|
|
// It follows time.RFC3339 and is applied unless timestamps are disabled.
|
|
defaultTimestampFormat = time.RFC3339
|
|
|
|
// defaultFields is the number of commonly included predefined log entry fields
|
|
// (msg, level, time). It is used as a capacity hint when constructing
|
|
// intermediate collections during formatting (for example, the fixed key list).
|
|
//
|
|
// It does not include the optional "logrus_error", "func", or "file" fields.
|
|
defaultFields = 3
|
|
)
|
|
|
|
// Default key names for the default fields
|
|
const (
|
|
FieldKeyMsg = "msg"
|
|
FieldKeyLevel = "level"
|
|
FieldKeyTime = "time"
|
|
FieldKeyLogrusError = "logrus_error"
|
|
FieldKeyFunc = "func"
|
|
FieldKeyFile = "file"
|
|
)
|
|
|
|
// Formatter is implemented by types that format log entries. It receives an
|
|
// [*Entry], which contains:
|
|
//
|
|
// - entry.Message: the message passed to logging methods such as [Info], [Warn], [Error]
|
|
// - entry.Time: the timestamp
|
|
// - entry.Level: the log level
|
|
//
|
|
// Additional fields added with [WithField] or [WithFields] are available in
|
|
// [Entry.Data]. Format should return the formatted log entry as a byte slice,
|
|
// which is written to [Logger.Out].
|
|
type Formatter interface {
|
|
Format(*Entry) ([]byte, error)
|
|
}
|
|
|
|
// This is to not silently overwrite `time`, `msg`, `func` 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, fieldMap FieldMap, reportCaller bool) {
|
|
timeKey := fieldMap.resolve(FieldKeyTime)
|
|
if t, ok := data[timeKey]; ok {
|
|
data["fields."+timeKey] = t
|
|
delete(data, timeKey)
|
|
}
|
|
|
|
msgKey := fieldMap.resolve(FieldKeyMsg)
|
|
if m, ok := data[msgKey]; ok {
|
|
data["fields."+msgKey] = m
|
|
delete(data, msgKey)
|
|
}
|
|
|
|
levelKey := fieldMap.resolve(FieldKeyLevel)
|
|
if l, ok := data[levelKey]; ok {
|
|
data["fields."+levelKey] = l
|
|
delete(data, levelKey)
|
|
}
|
|
|
|
logrusErrKey := fieldMap.resolve(FieldKeyLogrusError)
|
|
if l, ok := data[logrusErrKey]; ok {
|
|
data["fields."+logrusErrKey] = l
|
|
delete(data, logrusErrKey)
|
|
}
|
|
|
|
// If reportCaller is not set, 'func' will not conflict.
|
|
if reportCaller {
|
|
funcKey := fieldMap.resolve(FieldKeyFunc)
|
|
if l, ok := data[funcKey]; ok {
|
|
data["fields."+funcKey] = l
|
|
}
|
|
fileKey := fieldMap.resolve(FieldKeyFile)
|
|
if l, ok := data[fileKey]; ok {
|
|
data["fields."+fileKey] = l
|
|
}
|
|
}
|
|
}
|