You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Human-readable log formatter, converts logrus fields to a nested structure:
Configuration:
typeFormatterstruct {
// FieldsOrder - default: fields sorted alphabeticallyFieldsOrder []string// TimestampFormat - default: time.StampMilli = "Jan _2 15:04:05.000"TimestampFormatstring// HideKeys - show [fieldValue] instead of [fieldKey:fieldValue]HideKeysbool// NoColors - disable colorsNoColorsbool// NoFieldsColors - apply colors only to the level, default is level + fieldsNoFieldsColorsbool// NoFieldsSpace - no space between fieldsNoFieldsSpacebool// ShowFullLevel - show a full level [WARNING] instead of [WARN]ShowFullLevelbool// NoUppercaseLevel - no upper case for level valueNoUppercaseLevelbool// TrimMessages - trim whitespaces on messagesTrimMessagesbool// CallerFirst - print caller info firstCallerFirstbool// CustomCallerFormatter - set custom formatter for caller infoCustomCallerFormatterfunc(*runtime.Frame) string
}
Usage
import (
nested "github.com/antonfisher/nested-logrus-formatter""github.com/sirupsen/logrus"
)
log:=logrus.New()
log.SetFormatter(&nested.Formatter{
HideKeys: true,
FieldsOrder: []string{"component", "category"},
})
log.Info("just info message")
// Output: Jan _2 15:04:05.000 [INFO] just info messagelog.WithField("component", "rest").Warn("warn message")
// Output: Jan _2 15:04:05.000 [WARN] [rest] warn message