encoder

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package encoder provides the encoder to encode the log message.

Index

Constants

This section is empty.

Variables

View Source
var Now = time.Now

Now is used to get the current time.

Functions

This section is empty.

Types

type BoolEncoder

type BoolEncoder interface {
	EncodeBool(dst []byte, key string, value bool) []byte
}

BoolEncoder is used to encode the value typed bool.

type DurationEncoder

type DurationEncoder interface {
	EncodeDuration(dst []byte, key string, value time.Duration) []byte
}

DurationEncoder is used to encode the value typed time.Duration.

type Float64Encoder

type Float64Encoder interface {
	EncodeFloat64(dst []byte, key string, value float64) []byte
}

Float64Encoder is used to encode the key and the value typed float64.

type Int64Encoder

type Int64Encoder interface {
	EncodeInt64(dst []byte, key string, value int64) []byte
}

Int64Encoder is used to encode the key and the value typed int64.

type IntEncoder

type IntEncoder interface {
	EncodeInt(dst []byte, key string, value int) []byte
}

IntEncoder is used to encode the key and the value typed int.

type JSONEncoder

type JSONEncoder struct {
	kvjson.JSON

	// If true, append a newline when emit the log record.
	//
	// Default: true
	Newline bool

	// TimeKey is the key name of the time when to emit the log record if not empty.
	//
	// Default: "t"
	TimeKey string

	// LevelKey is the key name of the level if not empty.
	//
	// Default: "lvl"
	LevelKey string

	// LoggerKey is the key name of the logger name.
	//
	// Default: "logger"
	LoggerKey string

	// MsgKey is the key name of the message.
	//
	// Default: "msg"
	MsgKey string
}

JSONEncoder is a log encoder to encode the log record as JSON.

func NewJSONEncoder

func NewJSONEncoder() *JSONEncoder

NewJSONEncoder returns a new JSONEncoder.

If formatLevel is nil, disable to format the level.

func (*JSONEncoder) Encode

func (enc *JSONEncoder) Encode(buf []byte, key string, value interface{}) []byte

Encode implements the interface Encoder by using kvjson.JSON.EncodeKV.

func (*JSONEncoder) EncodeBool

func (enc *JSONEncoder) EncodeBool(dst []byte, key string, value bool) []byte

EncodeBool implements the interface BoolEncoder.

func (*JSONEncoder) EncodeDuration

func (enc *JSONEncoder) EncodeDuration(dst []byte, key string, value time.Duration) []byte

EncodeDuration implements the interface DurationEncoder.

func (*JSONEncoder) EncodeFloat64

func (enc *JSONEncoder) EncodeFloat64(dst []byte, key string, value float64) []byte

EncodeFloat64 implements the interface Float64Encoder.

func (*JSONEncoder) EncodeInt

func (enc *JSONEncoder) EncodeInt(dst []byte, key string, value int) []byte

EncodeInt implements the interface IntEncoder.

func (*JSONEncoder) EncodeInt64

func (enc *JSONEncoder) EncodeInt64(dst []byte, key string, value int64) []byte

EncodeInt64 implements the interface Int64Encoder.

func (*JSONEncoder) EncodeString

func (enc *JSONEncoder) EncodeString(dst []byte, key string, value string) []byte

EncodeString implements the interface StringEncoder.

func (*JSONEncoder) EncodeStringSlice added in v0.12.0

func (enc *JSONEncoder) EncodeStringSlice(dst []byte, key string, value []string) []byte

EncodeStringSlice implements the interface StringSliceEncoder.

func (*JSONEncoder) EncodeTime

func (enc *JSONEncoder) EncodeTime(dst []byte, key string, value time.Time) []byte

EncodeTime implements the interface TimeEncoder.

func (*JSONEncoder) EncodeUint

func (enc *JSONEncoder) EncodeUint(dst []byte, key string, value uint) []byte

EncodeUint implements the interface UintEncoder.

func (*JSONEncoder) EncodeUint64

func (enc *JSONEncoder) EncodeUint64(dst []byte, key string, value uint64) []byte

EncodeUint64 implements the interface Uint64Encoder.

func (*JSONEncoder) End

func (enc *JSONEncoder) End(buf []byte, msg string) []byte

End implements the interface Encoder.

func (*JSONEncoder) Start

func (enc *JSONEncoder) Start(buf []byte, name, level string) []byte

Start implements the interface Encoder.

type StringEncoder

type StringEncoder interface {
	EncodeString(dst []byte, key string, value string) []byte
}

StringEncoder is used to encode the value typed string.

type StringSliceEncoder added in v0.12.0

type StringSliceEncoder interface {
	EncodeStringSlice(dst []byte, key string, value []string) []byte
}

StringSliceEncoder is used to encode the value typed []string.

type TimeEncoder

type TimeEncoder interface {
	EncodeTime(dst []byte, key string, value time.Time) []byte
}

TimeEncoder is used to encode the value typed time.Time.

type Uint64Encoder

type Uint64Encoder interface {
	EncodeUint64(dst []byte, key string, value uint64) []byte
}

Uint64Encoder is used to encode the key and the value typed uint64.

type UintEncoder

type UintEncoder interface {
	EncodeUint(dst []byte, key string, value uint) []byte
}

UintEncoder is used to encode the key and the value typed uint.

Directories

Path Synopsis
Package kvjson is used to encode the json key-value pair.
Package kvjson is used to encode the json key-value pair.

Jump to

Keyboard shortcuts

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