formatter

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Color

func Color(l level.LogLevel) string

func SetLoggerName added in v0.4.0

func SetLoggerName(name string)

Types

type BaseFormatter added in v0.4.0

type BaseFormatter struct {
	*TimeFormatter
	// contains filtered or unexported fields
}

func NewBaseFormatter added in v0.4.0

func NewBaseFormatter(cfg BaseFormatterConfig) *BaseFormatter

func (*BaseFormatter) ConvertToMessage added in v0.4.0

func (b *BaseFormatter) ConvertToMessage(e *message.Entry) *message.Message

type BaseFormatterConfig added in v0.4.0

type BaseFormatterConfig struct {
	// time layout string, for example: "2006-01-02 15:04:05.000"
	TimeLayout string
	// enable color rendering
	EnableColor bool
	// short level string, for example: "Err" instead of "Error"
	ShortLevel bool
	// record pid in message
	EnablePid bool
	// record ip in message
	EnableIP bool
	// record hostname in message
	EnableHostname bool
	// record timestamp(int64 ms) in message
	EnableTimestamp bool
}

type IFormatter

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

type JSONFormatter

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

func NewJSONFormatter

func NewJSONFormatter(cfg JSONFormatterConfig) *JSONFormatter

func (*JSONFormatter) Format

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

type JSONFormatterConfig added in v0.4.0

type JSONFormatterConfig struct {
	BaseFormatterConfig
	DisableHTMLEscape bool // [json formatter] allows disabling html escaping in output.
	PrettyPrint       bool // [json|xml formatter] will indent all json logs.

}

type TextFormatter

type TextFormatter struct {
	*BaseFormatter

	EnableQuote            bool
	EnableQuoteEmptyFields bool
	DisableColors          bool
	// contains filtered or unexported fields
}

TextFormatter formats logs into text

func NewTextFormatter

func NewTextFormatter(cfg TextFormatterConfig) *TextFormatter

func (*TextFormatter) ColorRender

func (f *TextFormatter) ColorRender(b *bytes.Buffer, m *message.Message)

func (*TextFormatter) ColorRenderV2

func (f *TextFormatter) ColorRenderV2(b *bytes.Buffer, m *message.Message)

func (*TextFormatter) Format

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

Format renders log's message into bytes

type TextFormatterConfig added in v0.4.0

type TextFormatterConfig struct {
	BaseFormatterConfig
	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.

}

type TimeFormatter added in v0.4.0

type TimeFormatter struct {
	SecondLayout string
	// contains filtered or unexported fields
}

func NewTimeFormatter added in v0.4.0

func NewTimeFormatter(layout string) *TimeFormatter

func (*TimeFormatter) FormatDateTime added in v0.4.0

func (tf *TimeFormatter) FormatDateTime(t time.Time) string

FormatDateTime Influenced by parallelism, small probability took the old value. Because it is logging, we don't make it so strict

func (*TimeFormatter) SetTimeDecimalFormat added in v0.4.0

func (tf *TimeFormatter) SetTimeDecimalFormat(decimal int)

type XMLFormatter

type XMLFormatter struct {
	*BaseFormatter
	PrettyPrint bool
}

func NewXMLFormatter

func NewXMLFormatter(cfg XMLFormatterConfig) *XMLFormatter

func (*XMLFormatter) Format

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

type XMLFormatterConfig added in v0.4.0

type XMLFormatterConfig struct {
	BaseFormatterConfig
	PrettyPrint bool // [json|xml formatter] will indent all json logs.
}

Jump to

Keyboard shortcuts

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