formatter

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 6 Imported by: 737

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	FieldsOrder     []string // default: fields sorted alphabetically
	TimestampFormat string   // default: time.StampMilli = "Jan _2 15:04:05.000"
	HideKeys        bool     // show [fieldValue] instead of [fieldKey:fieldValue]
	NoColors        bool     // disable colors
	NoFieldsColors  bool     // color only level, default is level + fields
	ShowFullLevel   bool     // true to show full level [WARNING] instead [WARN]
	TrimMessages    bool     // true to trim whitespace on messages
}

Formatter - logrus formatter, implements logrus.Formatter

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

Format an log entry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL