humanize

package
v0.0.0-...-49b44fb Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HumanizeFormatVar = "HUMANIZE"
	FormatFull        = "FULL"
	FormatCompact     = "COMPACT"
	FormatJSON        = "JSON"
)

Log-level configuration from env vars

Variables

View Source
var DefaultLevelColors = map[logrus.Level]int{
	logrus.DebugLevel: blue,
	logrus.ErrorLevel: red,
	logrus.FatalLevel: red,
	logrus.WarnLevel:  yellow,
	logrus.TraceLevel: grey,
	logrus.PanicLevel: red,
}
View Source
var ElementColors = map[string]int{
	"date":   grey,
	"time":   blue,
	"caller": green,
}

Functions

func NewHumanizeFormatterFromEnv

func NewHumanizeFormatterFromEnv() (logrus.Formatter, error)

NewHumanizeFormatterFromEnv reads a configuration variable from the environment, using it to configure and return a logger. Humanize looks for its configuration using the value of the `HumanizeFormatVar` constant, and can respond to one of three values:

  1. FULL -> Format using long formatting (this is the default).
  2. COMPACT -> Format using compact formatting.
  3. JSON -> Return the default Fallback formatter, logrus.JSONFormatter

Types

type Formatter

type Formatter struct {
	// It's possible you don't want ISO-8601. You're wrong, but... OK.
	DateTimeFormat string
	// Take up more whitespace or less.
	Compact bool
	// We assume you wont want to ship logs to logstash or what have you in this
	// format. What do we use when a human isn't looking?
	Fallback logrus.Formatter
	// contains filtered or unexported fields
}

Formatter renders Logrus log lines in a nicer format for humans.

func NewHumanizeFormatter

func NewHumanizeFormatter() *Formatter

NewHumanizeFormatter creates a new formatter with defaults set.

func (*Formatter) Format

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

Format implements the Formatter interfact for our Formatter.

Jump to

Keyboard shortcuts

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