format

package
v0.67.13 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package format provides a logrus formatter that formats log entries in a structured way.

Index

Constants

View Source
const (
	PrefixKeyName   = "prefix"
	TFBinaryKeyName = "tfBinary"
)
View Source
const (
	FieldKeyMsg         = "msg"
	FieldKeyLevel       = "level"
	FieldKeyTime        = "time"
	FieldKeyLogrusError = "logrus_error"
	FieldKeyFunc        = "func"
	FieldKeyFile        = "file"
)

Default key names for the default fields.

Variables

This section is empty.

Functions

func NewPrefixStyle

func NewPrefixStyle() *prefixStyle

Types

type ColorFunc

type ColorFunc func(string) string

type ColorScheme

type ColorScheme map[ColorStyleName]ColorStyle

func (ColorScheme) Compile

func (scheme ColorScheme) Compile() compiledColorScheme

type ColorStyle

type ColorStyle string

func (ColorStyle) ColorFunc

func (style ColorStyle) ColorFunc() ColorFunc

type ColorStyleName

type ColorStyleName byte
const (
	None ColorStyleName = iota
	InfoLevelStyle
	WarnLevelStyle
	ErrorLevelStyle
	FatalLevelStyle
	PanicLevelStyle
	DebugLevelStyle
	TraceLevelStyle
	TFBinaryStyle
	TimestampStyle
)

type FieldMap

type FieldMap map[fieldKey]string

FieldMap allows customization of the key names for default fields.

type Formatter

type Formatter struct {
	// Disable formatted layout
	DisableLogFormatting bool

	// Force disabling colors. For a TTY colors are enabled by default.
	DisableColors bool

	// Disable the conversion of the log levels to uppercase
	DisableUppercase bool

	// Timestamp format to use for display when a full timestamp is printed.
	TimestampFormat string

	// The fields are sorted by default for a consistent output.
	DisableSorting bool

	// Wrap empty fields in quotes if true.
	QuoteEmptyFields bool

	// Can be set to the override the default quoting character " with something else. For example: ', or `.
	QuoteCharacter string

	// PrefixStyle is used to assign different styles (colors) to each prefix.
	PrefixStyle PrefixStyle
	// contains filtered or unexported fields
}

func NewFormatter

func NewFormatter() *Formatter

NewFormatter returns a new Formatter instance with default values.

func (*Formatter) Format

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

Format implements logrus.Formatter

func (*Formatter) SetColorScheme

func (formatter *Formatter) SetColorScheme(colorScheme *ColorScheme)

type JSONFormatter

type JSONFormatter struct {
	// TimestampFormat sets the format used for marshaling timestamps.
	TimestampFormat string

	// DisableTimestamp allows disabling automatic timestamps in output.
	DisableTimestamp bool

	// DisableHTMLEscape allows disabling html escaping in output.
	DisableHTMLEscape bool

	// DataKey allows users to put all the log entry parameters into a nested dictionary at a given key.
	DataKey string

	// FieldMap allows users to customize the names of keys for default fields.
	FieldMap FieldMap

	// PrettyPrint will indent all json logs.
	PrettyPrint bool
}

JSONFormatter formats logs into parsable json.

func (*JSONFormatter) Format

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

Format implements logrus.Formatter interface.

type PrefixStyle

type PrefixStyle interface {
	// ColorFunc creates a closure to avoid computation ANSI color code.
	ColorFunc(prefixName string) ColorFunc
}

type SilentFormatter

type SilentFormatter struct{}

SilentFormatter disables logging by not outputting anything.

func (*SilentFormatter) Format

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

Format implements logrus.Formatter interface.

Jump to

Keyboard shortcuts

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