Documentation
¶
Index ¶
- Constants
- type Field
- func Any(k string, v any) Field
- func Bool(k string, v bool) Field
- func Bools(k string, v []bool) Field
- func Dict(k string, fields ...Field) Field
- func Duration(k string, v time.Duration) Field
- func Error(err error) Field
- func Errors(k string, v []error) Field
- func Float64(k string, v float64) Field
- func Float64s(k string, v []float64) Field
- func From(k string, v any) Field
- func Hex(k string, b []byte) Field
- func Int(k string, v int) Field
- func Int64(k string, v int64) Field
- func Int64s(k string, v []int64) Field
- func Lazy(fn func() []Field) Field
- func LazyFields(fn func(context.Context) []Field) Field
- func NamedError(k string, err error) Field
- func Nop() Field
- func RawJSON(k string, json []byte) Field
- func String(k, v string) Field
- func Strings(k string, v []string) Field
- func TimeField(k string, v time.Time) Field
- func Timestamp(t time.Time) Field
- func TimestampAt(k string, t time.Time) Field
- func Uint(k string, v uint) Field
- func Uint64(k string, v uint64) Field
- func Uint64s(k string, v []uint64) Field
- type FieldKind
Constants ¶
const ( ErrorKey = "error" TimestampKey = "ts" )
Conventional keys used by helpers.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
Field is a portable structured field: a key plus a typed value. The unexported 'kind' enforces invariants via the constructors below.
func Dict ¶
Dict groups sub-fields under a single key (zap: Object, slog: Group). NOTE: this does not copy the slice; pass a copy if you will mutate it.
func Error ¶
Error adds a non-nil error under the conventional key ("error"). If err is nil, returns a no-op.
func LazyFields ¶
LazyFields runs lazily at log time (only if enabled) and returns extra fields to append. NOTE: The function should be fast and side-effect free.
func NamedError ¶
NamedError adds a non-nil error with a custom key. If err is nil, returns a no-op.
func RawJSON ¶
RawJSON inserts pre-encoded JSON bytes under key. NOTE: Backends that don’t support raw JSON may encode it as a string or bytes (eg zap supports; slog may treat as []byte/string).
func Timestamp ¶
Timestamp asks the backend to attach a timestamp field. If t is zero, backends should use time.Now(); otherwise use t. The key defaults to TimestampKey ("ts"); backends may honor Options.TimeLayout.
func TimestampAt ¶
TimestampAt is the same as Timestamp but with a custom key.
type FieldKind ¶
type FieldKind uint8
FieldKind describes the concrete type carried by a Field's value.
const ( FieldKindInvalid FieldKind = iota // zero / no-op FieldKindAny // Scalars FieldKindString FieldKindBool FieldKindInt64 FieldKindUint64 FieldKindFloat64 FieldKindTime FieldKindDuration FieldKindError // Slices FieldKindStrings FieldKindBools FieldKindInt64s FieldKindUint64s FieldKindFloat64s FieldKindErrors // Special FieldKindDict // sub-fields (Value is []Field) FieldKindRawJSON // []byte that is already JSON FieldKindHexBytes // []byte to render as hex string FieldKindLazyFields // lazy: func(context.Context) []Field FieldKindLazyValue // lazy: func() []Field FieldKindTimestamp // backend inserts current timestamp (or uses Value as time.Time if provided) )