field

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 2 Imported by: 11

Documentation

Index

Constants

View Source
const (
	TimeKey    = "ts"
	LevelKey   = "level"
	LoggerKey  = "logger"
	MessageKey = "msg"
	ErrorKey   = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendFunc

type AppendFunc[T any] func(enc Encoder, key string, value T)

AppendFunc encodes a typed value as a field.

type CustomValue

type CustomValue interface {
	AppendXLog(enc Encoder, key string)
}

type Encoder

type Encoder interface {
	String(key, value string)
	Bool(key string, value bool)
	Int64(key string, value int64)
	Uint64(key string, value uint64)
	Float64(key string, value float64)
	Duration(key string, value time.Duration)
	Time(key string, value time.Time)
	Error(key string, err error)
	Any(key string, value any)
	Null(key string)
}

Encoder is the target API for fields.

It is intentionally format-agnostic: JSON, zap, slog, and other backends implement this interface in their own packages.

type Field

type Field struct {
	Key  string
	Kind Kind
	// contains filtered or unexported fields
}

Field is a structured logging field.

It is a concrete value type so built-in fields stay on the hot path without interface boxing. Extension points are represented by Custom, ValueOf, and Any.

func Any

func Any(key string, value any) Field

func Bool

func Bool(key string, value bool) Field

func Custom

func Custom(key string, value CustomValue) Field

func CustomFunc

func CustomFunc(key string, value any, append func(enc Encoder, key string, value any)) Field

func Duration

func Duration(key string, value time.Duration) Field

func Err

func Err(err error) Field

func Error

func Error(key string, err error) Field

func Float64

func Float64(key string, value float64) Field

func Generic

func Generic[T any](key string, value T, append AppendFunc[T]) Field

func Int

func Int(key string, value int) Field

func Int64

func Int64(key string, value int64) Field

func String

func String(key, value string) Field

func Time

func Time(key string, value time.Time) Field

func Uint

func Uint(key string, value uint) Field

func Uint64

func Uint64(key string, value uint64) Field

func ValueOf

func ValueOf[T Value](key string, value T) Field

func (Field) AnyValue

func (f Field) AnyValue() any

func (Field) AppendCustom

func (f Field) AppendCustom(enc Encoder)

func (Field) BoolValue

func (f Field) BoolValue() bool

func (Field) DurationValue

func (f Field) DurationValue() time.Duration

func (Field) ErrorValue

func (f Field) ErrorValue() error

func (Field) Float64Value

func (f Field) Float64Value() float64

func (Field) Int64Value

func (f Field) Int64Value() int64

func (Field) StringValue

func (f Field) StringValue() string

func (Field) TimeValue

func (f Field) TimeValue() time.Time

func (Field) Uint64Value

func (f Field) Uint64Value() uint64

type Kind

type Kind uint8
const (
	SkipKind Kind = iota
	StringKind
	BoolKind
	Int64Kind
	Uint64Kind
	Float64Kind
	DurationKind
	TimeKind
	ErrorKind
	AnyKind
	CustomKind
)

type Value

type Value interface {
	AppendXLog(enc Encoder, key string)
}

Value can be implemented by domain types that know how to encode themselves into an xlog field.

Jump to

Keyboard shortcuts

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