nested-logrus-formatter
Human-readable log formatter, converts logrus fields to a nested structure:
Configuration:
type Formatter struct {
FieldsOrder []string // by default fields are sorted alphabetically
TimestampFormat string // by default time.StampMilli = "Jan _2 15:04:05.000" is used
HideKeys bool // to show only [fieldValue] instead of [fieldKey:fieldValue]
NoColors bool // to disable all colors
NoFieldsColors bool // to disable colors only on fields and keep levels colored
ShowFullLevel bool // to show full level (e.g. [WARNING] instead of [WARN])
TrimMessages bool // to trim whitespace on messages
}
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 message
log.WithField("component", "rest").Warn("warn message")
// Output: Jan _2 15:04:05.000 [WARN] [rest] warn message
Development
# run tests:
make test
# run demo:
make demo