entry

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFormatter = NewTextFormatter(nil)

DefaultFormatter is the global default formatter, useful when in case of nil Formatter, or simply wanting defaults.

Functions

This section is empty.

Types

type Entry

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

Entry represents a single entry in a log. It provides methods for writing formatted data to a byte buffer before making a singular write to an io.Writer.

func NewEntry

func NewEntry(b []byte, fmt Formatter) *Entry

NewEntry returns a new Entry initialized with buffer.

func (*Entry) Buffer

func (e *Entry) Buffer() *byteutil.Buffer

Buffer returns the underlying format buffer.

func (*Entry) Bytes

func (e *Entry) Bytes() []byte

Bytes returns the currently accumulated entry buffer bytes.

func (*Entry) Caller

func (e *Entry) Caller(calldepth int)

Caller will write formatted caller information to the entry.

func (*Entry) Context

func (e *Entry) Context() context.Context

Context returns the context associated with this entry.

func (*Entry) Field

func (e *Entry) Field(key string, value interface{})

Field will write formatted key-value pair as field to the entry.

func (*Entry) Fields

func (e *Entry) Fields(fields ...kv.Field)

Fields will write formatted key-value fields to the entry.

func (*Entry) Level

func (e *Entry) Level() level.LEVEL

Level returns the currently set entry level.

func (*Entry) Msg

func (e *Entry) Msg(a ...interface{})

Msg will write given arguments as message to the entry.

func (*Entry) Msgf

func (e *Entry) Msgf(s string, a ...interface{})

Msgf will write given format string and arguments as message to the entry.

func (*Entry) Reset

func (e *Entry) Reset()

Reset will reset the entry's current context, level and buffer.

func (*Entry) SetFormat

func (e *Entry) SetFormat(fmt Formatter)

SetFormat will update the entry's formatter to provided.

func (*Entry) String

func (e *Entry) String() string

String returns the currently accumulated entry buffer bytes as string, please note this points to the underlying byte slice.

func (*Entry) Timestamp

func (e *Entry) Timestamp()

Timestamp will write formatted timestamp to the entry.

func (*Entry) WithContext

func (e *Entry) WithContext(ctx context.Context)

WithContext updates the entry to use the provided context.

func (*Entry) WithLevel

func (e *Entry) WithLevel(lvl level.LEVEL)

WithLevel updates the entry to provided level and writes formatted level to the entry.

type FieldFormatter

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

FieldFormatter is a level.Levels typedef to implement the Formatter interface, in a manner that provides logging with timestamp, caller info and level prefixing log entries in key-value formatting.

func (*FieldFormatter) Caller

func (f *FieldFormatter) Caller(buf *byteutil.Buffer, calldepth int)

func (*FieldFormatter) Fields

func (f *FieldFormatter) Fields(buf *byteutil.Buffer, fields []kv.Field)

func (*FieldFormatter) Level

func (f *FieldFormatter) Level(buf *byteutil.Buffer, lvl level.LEVEL)

func (*FieldFormatter) Msg

func (f *FieldFormatter) Msg(buf *byteutil.Buffer, a ...interface{})

func (*FieldFormatter) Msgf

func (f *FieldFormatter) Msgf(buf *byteutil.Buffer, s string, a ...interface{})

func (*FieldFormatter) Timestamp

func (f *FieldFormatter) Timestamp(buf *byteutil.Buffer)

type Formatter

type Formatter interface {
	// Level will append formatted level string to buffer.
	Level(buf *byteutil.Buffer, lvl level.LEVEL)

	// Timestamp will append formatted timestamp string to buffer.
	Timestamp(buf *byteutil.Buffer)

	// Caller will append formatted caller information to buffer.
	Caller(buf *byteutil.Buffer, calldepth int)

	// Fields will append formatted key-value fields to buffer.
	Fields(buf *byteutil.Buffer, fields []kv.Field)

	// Msg will append formatted msg arguments to buffer.
	Msg(buf *byteutil.Buffer, args ...interface{})

	// Msgf will append formatted msg format string with arguments to buffer.
	Msgf(buf *byteutil.Buffer, format string, args ...interface{})
}

Formatter provides formatting for various standard data types being written to an entry's format buffer.

func NewFieldFormatter

func NewFieldFormatter(lvls *level.Levels) Formatter

NewFieldFormatter returns a prepared FieldFormatter instance, using provided level.Levels for printing of level strings, else uses defaults.

func NewTextFormatter

func NewTextFormatter(lvls *level.Levels) Formatter

NewTextFormatter returns a prepared TextFormatter instance, using provided level.Levels for printing of level strings, else uses defaults.

type TextFormatter

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

TextFormatter is a Levels typedef to implement the Formatter interface, in a manner that provides logging with timestamp, caller info and level prefixing log entries in plain printed text.

func (*TextFormatter) Caller

func (f *TextFormatter) Caller(buf *byteutil.Buffer, calldepth int)

func (*TextFormatter) Fields

func (f *TextFormatter) Fields(buf *byteutil.Buffer, fields []kv.Field)

func (*TextFormatter) Level

func (f *TextFormatter) Level(buf *byteutil.Buffer, lvl level.LEVEL)

func (*TextFormatter) Msg

func (f *TextFormatter) Msg(buf *byteutil.Buffer, a ...interface{})

func (*TextFormatter) Msgf

func (f *TextFormatter) Msgf(buf *byteutil.Buffer, s string, a ...interface{})

func (*TextFormatter) Timestamp

func (f *TextFormatter) Timestamp(buf *byteutil.Buffer)

Jump to

Keyboard shortcuts

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