// Array constructs a field with the given key and ArrayMarshaler. It provides // a flexible, but still type-safe and efficient, way to add array-like types // to the logging context. The struct's MarshalLogArray method is called lazily. func Array(key string, val zapcore.ArrayMarshaler) Field { … } // Bools constructs a field that carries a slice of bools. func Bools(key string, bs []bool) Field { … } // ByteStrings constructs a field that carries a slice of []byte, each of which // must be UTF-8 encoded text. func ByteStrings(key string, bss [][]byte) Field { … } // Complex128s constructs a field that carries a slice of complex numbers. func Complex128s(key string, nums []complex128) Field { … } // Complex64s constructs a field that carries a slice of complex numbers. func Complex64s(key string, nums []complex64) Field { … } // Durations constructs a field that carries a slice of time.Durations. func Durations(key string, ds []time.Duration) Field { … } // Float64s constructs a field that carries a slice of floats. func Float64s(key string, nums []float64) Field { … } // Float32s constructs a field that carries a slice of floats. func Float32s(key string, nums []float32) Field { … } // Ints constructs a field that carries a slice of integers. func Ints(key string, nums []int) Field { … } // Int64s constructs a field that carries a slice of integers. func Int64s(key string, nums []int64) Field { … } // Int32s constructs a field that carries a slice of integers. func Int32s(key string, nums []int32) Field { … } // Int16s constructs a field that carries a slice of integers. func Int16s(key string, nums []int16) Field { … } // Int8s constructs a field that carries a slice of integers. func Int8s(key string, nums []int8) Field { … } // Objects constructs a field with the given key, holding a list of the // provided objects that can be marshaled by Zap. // // Note that these objects must implement zapcore.ObjectMarshaler directly. // That is, if you're trying to marshal a []Request, the MarshalLogObject // method must be declared on the Request type, not its pointer (*Request). // If it's on the pointer, use ObjectValues. // // Given an object that implements MarshalLogObject on the value receiver, you // can log a slice of those objects with Objects like so: // // type Author struct{ ... } // func (a Author) MarshalLogObject(enc zapcore.ObjectEncoder) error // // var authors []Author = ... // logger.Info("loading article", zap.Objects("authors", authors)) // // Similarly, given a type that implements MarshalLogObject on its pointer // receiver, you can log a slice of pointers to that object with Objects like // so: // // type Request struct{ ... } // func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error // // var requests []*Request = ... // logger.Info("sending requests", zap.Objects("requests", requests)) // // If instead, you have a slice of values of such an object, use the // ObjectValues constructor. // // var requests []Request = ... // logger.Info("sending requests", zap.ObjectValues("requests", requests)) func Objects[T zapcore.ObjectMarshaler](key string, values []T) Field { … } type objects … func (os objects[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type ObjectMarshalerPtr … // ObjectValues constructs a field with the given key, holding a list of the // provided objects, where pointers to these objects can be marshaled by Zap. // // Note that pointers to these objects must implement zapcore.ObjectMarshaler. // That is, if you're trying to marshal a []Request, the MarshalLogObject // method must be declared on the *Request type, not the value (Request). // If it's on the value, use Objects. // // Given an object that implements MarshalLogObject on the pointer receiver, // you can log a slice of those objects with ObjectValues like so: // // type Request struct{ ... } // func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error // // var requests []Request = ... // logger.Info("sending requests", zap.ObjectValues("requests", requests)) // // If instead, you have a slice of pointers of such an object, use the Objects // field constructor. // // var requests []*Request = ... // logger.Info("sending requests", zap.Objects("requests", requests)) func ObjectValues[T any, P ObjectMarshalerPtr[T]](key string, values []T) Field { … } type objectValues … func (os objectValues[T, P]) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } // Strings constructs a field that carries a slice of strings. func Strings(key string, ss []string) Field { … } // Stringers constructs a field with the given key, holding a list of the // output provided by the value's String method // // Given an object that implements String on the value receiver, you // can log a slice of those objects with Objects like so: // // type Request struct{ ... } // func (a Request) String() string // // var requests []Request = ... // logger.Info("sending requests", zap.Stringers("requests", requests)) // // Note that these objects must implement fmt.Stringer directly. // That is, if you're trying to marshal a []Request, the String method // must be declared on the Request type, not its pointer (*Request). func Stringers[T fmt.Stringer](key string, values []T) Field { … } type stringers … func (os stringers[T]) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } // Times constructs a field that carries a slice of time.Times. func Times(key string, ts []time.Time) Field { … } // Uints constructs a field that carries a slice of unsigned integers. func Uints(key string, nums []uint) Field { … } // Uint64s constructs a field that carries a slice of unsigned integers. func Uint64s(key string, nums []uint64) Field { … } // Uint32s constructs a field that carries a slice of unsigned integers. func Uint32s(key string, nums []uint32) Field { … } // Uint16s constructs a field that carries a slice of unsigned integers. func Uint16s(key string, nums []uint16) Field { … } // Uint8s constructs a field that carries a slice of unsigned integers. func Uint8s(key string, nums []uint8) Field { … } // Uintptrs constructs a field that carries a slice of pointer addresses. func Uintptrs(key string, us []uintptr) Field { … } // Errors constructs a field that carries a slice of errors. func Errors(key string, errs []error) Field { … } type bools … func (bs bools) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type byteStringsArray … func (bss byteStringsArray) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type complex128s … func (nums complex128s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type complex64s … func (nums complex64s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type durations … func (ds durations) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type float64s … func (nums float64s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type float32s … func (nums float32s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type ints … func (nums ints) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type int64s … func (nums int64s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type int32s … func (nums int32s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type int16s … func (nums int16s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type int8s … func (nums int8s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type stringArray … func (ss stringArray) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type times … func (ts times) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type uints … func (nums uints) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type uint64s … func (nums uint64s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type uint32s … func (nums uint32s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type uint16s … func (nums uint16s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type uint8s … func (nums uint8s) MarshalLogArray(arr zapcore.ArrayEncoder) error { … } type uintptrs … func (nums uintptrs) MarshalLogArray(arr zapcore.ArrayEncoder) error { … }