formatter

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 14 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
}

func (BaseFormatterConfig) WithEnableColor added in v0.4.1

func (c BaseFormatterConfig) WithEnableColor() BaseFormatterConfig

func (BaseFormatterConfig) WithEnableHostname added in v0.4.1

func (c BaseFormatterConfig) WithEnableHostname() BaseFormatterConfig

func (BaseFormatterConfig) WithEnableIP added in v0.4.1

func (c BaseFormatterConfig) WithEnableIP() BaseFormatterConfig

func (BaseFormatterConfig) WithEnablePid added in v0.4.1

func (c BaseFormatterConfig) WithEnablePid() BaseFormatterConfig

func (BaseFormatterConfig) WithEnableTimestamp added in v0.4.1

func (c BaseFormatterConfig) WithEnableTimestamp() BaseFormatterConfig

func (BaseFormatterConfig) WithShortLevel added in v0.4.1

func (c BaseFormatterConfig) WithShortLevel() BaseFormatterConfig

func (BaseFormatterConfig) WithTimeLayout added in v0.4.1

func (c BaseFormatterConfig) WithTimeLayout(layout string) BaseFormatterConfig

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.

}

func (*JSONFormatterConfig) WithBaseFormatterConfig added in v0.4.1

func (c *JSONFormatterConfig) WithBaseFormatterConfig(baseCfg BaseFormatterConfig) *JSONFormatterConfig

func (*JSONFormatterConfig) WithDisableHTMLEscape added in v0.4.1

func (c *JSONFormatterConfig) WithDisableHTMLEscape() *JSONFormatterConfig

func (*JSONFormatterConfig) WithPrettyPrint added in v0.4.1

func (c *JSONFormatterConfig) WithPrettyPrint() *JSONFormatterConfig

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

func (*TextFormatterConfig) WithBaseFormatterConfig added in v0.4.1

func (c *TextFormatterConfig) WithBaseFormatterConfig(baseCfg BaseFormatterConfig) *TextFormatterConfig

func (*TextFormatterConfig) WithEnableQuote added in v0.4.1

func (c *TextFormatterConfig) WithEnableQuote() *TextFormatterConfig

func (*TextFormatterConfig) WithEnableQuoteEmptyFields added in v0.4.1

func (c *TextFormatterConfig) WithEnableQuoteEmptyFields() *TextFormatterConfig

func (*TextFormatterConfig) WithPatternStyle added in v0.4.1

func (c *TextFormatterConfig) WithPatternStyle(pattern string) *TextFormatterConfig

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

func (*XMLFormatterConfig) WithBaseFormatterConfig added in v0.4.1

func (c *XMLFormatterConfig) WithBaseFormatterConfig(baseCfg BaseFormatterConfig) *XMLFormatterConfig

func (*XMLFormatterConfig) WithPrettyPrint added in v0.4.1

func (c *XMLFormatterConfig) WithPrettyPrint() *XMLFormatterConfig

Jump to

Keyboard shortcuts

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