Skip to content

bluexlab/logrus-formatter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 - 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
}

Usage

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.

Development

# run tests:
make test

# run demo:
make demo

Packages

No packages published

Languages

  • Go 98.3%
  • Makefile 1.7%