Human-readable log formatter, converts logrus fields to a nested structure:
type Formatter struct {
// FieldsOrder - default: fields sorted alphabetically
FieldsOrder []string
// UseLocalTime - use local time
UseLocalTime bool
// TimestampFormat - default: RFC3339Milli "2006-01-02T15:04:05.000Z07:00"
TimestampFormat string
// HideKeys - show [fieldValue] instead of [fieldKey:fieldValue]
HideKeys bool
// NoColors - disable colors
NoColors bool
// NoFieldsColors - apply colors only to the level, default is level + fields
NoFieldsColors bool
// NoFieldsSpace - no space between fields
NoFieldsSpace bool
// ShowFullLevel - show a full level [WARNING] instead of [WARN]
ShowFullLevel bool
// NoUppercaseLevel - no upper case for level value
NoUppercaseLevel bool
// TrimMessages - trim whitespaces on messages
TrimMessages bool
// CallerFirst - print caller info first
CallerFirst bool
// CustomCallerFormatter - set custom formatter for caller info
CustomCallerFormatter func(*runtime.Frame) string
}
import (
formatter "github.com/bluexlab/logrus-formatter"
"github.com/sirupsen/logrus"
)
formatter.InitLogger()
logrus.Info("just info message")
// Output: 2006-01-02T15:04:05.999Z [INFO] just info message
log.WithField("component", "rest").Warn("warn message")
// Output: 2006-01-02T15:04:05.999Z [WARNING] [rest] warn message
See more examples in the tests file.
# run tests:
make test
# run demo:
make demo