formatter

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Color

func Color(l level.LogLevel) string

Types

type FormatterConfig added in v0.3.0

type FormatterConfig struct {
	FormatterType     FormatterType
	ExternalFormatter IFormatter
	TimestampFormat   string

	PatternStyle           string // [text formatter] style template for formatting the data, which determines the order of the fields and the presentation style.
	EnableQuote            bool   // [text formatter] keep the string literal, while escaping safely if necessary.
	EnableQuoteEmptyFields bool   // [text formatter] when the value of field is empty, keep the string literal.
	DisableColors          bool   // [text formatter] adding color rendering to the output.

	DisableTimestamp  bool // [json formatter] allows disabling automatic timestamps in output.
	DisableHTMLEscape bool // [json formatter] allows disabling html escaping in output.
	PrettyPrint       bool // [json|xml formatter] will indent all json logs.
}

type FormatterType added in v0.3.0

type FormatterType int
const (
	FormatterTypeText FormatterType = 1
	FormatterTypeJSON FormatterType = 2
	FormatterTypeXML  FormatterType = 3
)

type IFormatter

type IFormatter interface {
	Format(*message.Entry) ([]byte, error)
}

func GetNewFormatter

func GetNewFormatter(formatterCfg FormatterConfig) IFormatter

type JSONFormatter

type JSONFormatter struct {
	// contains filtered or unexported fields
}

func NewJSONFormatter

func NewJSONFormatter(formatterCfg FormatterConfig) *JSONFormatter

func (*JSONFormatter) Format

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

type TextFormatter

type TextFormatter struct {
	EnableQuote            bool
	EnableQuoteEmptyFields bool
	DisableColors          bool
	TimestampFormat        string
	// contains filtered or unexported fields
}

TextFormatter formats logs into text

func NewTextFormatter

func NewTextFormatter(formatterCfg FormatterConfig) *TextFormatter

func (*TextFormatter) ColorRender

func (f *TextFormatter) ColorRender(b *bytes.Buffer, entry *message.Entry)

func (*TextFormatter) ColorRenderV2

func (f *TextFormatter) ColorRenderV2(b *bytes.Buffer, entry *message.Entry)

func (*TextFormatter) Format

func (f *TextFormatter) Format(entry *message.Entry) ([]byte, error)

Format renders a single log entry

type XMLFormatter

type XMLFormatter struct {
	TimestampFormat string
	PrettyPrint     bool
}

func NewXMLFormatter

func NewXMLFormatter(formatterCfg FormatterConfig) *XMLFormatter

func (*XMLFormatter) Format

func (f *XMLFormatter) Format(entry *message.Entry) ([]byte, error)

Jump to

Keyboard shortcuts

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