Skip to content
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example feat: add NoFieldsColors option, fields with colors by default Oct 20, 2018
tests tests: add tests for TrimMessages option Apr 3, 2019
.gitignore docs: add godocs link Apr 3, 2019
.travis.yml chore: fix travis-ci Oct 20, 2018
LICENSE Initial commit Oct 16, 2018
Makefile chore: fix travis paths Oct 20, 2018
README.md docs: add godocs link Apr 3, 2019
formatter.go Add option to trim messages Apr 3, 2019

README.md

nested-logrus-formatter

Build Status Go Report Card GoDoc

Human-readable log formatter, converts logrus fields to a nested structure:

Screenshot

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
You can’t perform that action at this time.