package logrusimportconst (// 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 fieldsconst (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].typeFormatterinterface {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( Fields, FieldMap, bool) { := .resolve(FieldKeyTime)if , := []; { ["fields."+] = delete(, ) } := .resolve(FieldKeyMsg)if , := []; { ["fields."+] = delete(, ) } := .resolve(FieldKeyLevel)if , := []; { ["fields."+] = delete(, ) } := .resolve(FieldKeyLogrusError)if , := []; { ["fields."+] = delete(, ) }// If reportCaller is not set, 'func' will not conflict.if { := .resolve(FieldKeyFunc)if , := []; { ["fields."+] = } := .resolve(FieldKeyFile)if , := []; { ["fields."+] = } }}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.