// Copyright (c) 2016 Uber Technologies, Inc.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to deal// in the Software without restriction, including without limitation the rights// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell// copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in// all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN// THE SOFTWARE.package zapimport ()// 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 ( string, zapcore.ArrayMarshaler) Field {returnField{Key: , Type: zapcore.ArrayMarshalerType, Interface: }}// Bools constructs a field that carries a slice of bools.func ( string, []bool) Field {returnArray(, bools())}// ByteStrings constructs a field that carries a slice of []byte, each of which// must be UTF-8 encoded text.func ( string, [][]byte) Field {returnArray(, byteStringsArray())}// Complex128s constructs a field that carries a slice of complex numbers.func ( string, []complex128) Field {returnArray(, complex128s())}// Complex64s constructs a field that carries a slice of complex numbers.func ( string, []complex64) Field {returnArray(, complex64s())}// Durations constructs a field that carries a slice of time.Durations.func ( string, []time.Duration) Field {returnArray(, durations())}// Float64s constructs a field that carries a slice of floats.func ( string, []float64) Field {returnArray(, float64s())}// Float32s constructs a field that carries a slice of floats.func ( string, []float32) Field {returnArray(, float32s())}// Ints constructs a field that carries a slice of integers.func ( string, []int) Field {returnArray(, ints())}// Int64s constructs a field that carries a slice of integers.func ( string, []int64) Field {returnArray(, int64s())}// Int32s constructs a field that carries a slice of integers.func ( string, []int32) Field {returnArray(, int32s())}// Int16s constructs a field that carries a slice of integers.func ( string, []int16) Field {returnArray(, int16s())}// Int8s constructs a field that carries a slice of integers.func ( string, []int8) Field {returnArray(, int8s())}// 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 [ zapcore.ObjectMarshaler]( string, []) Field {returnArray(, objects[]())}typeobjects[ zapcore.ObjectMarshaler] []func ( objects[]) ( zapcore.ArrayEncoder) error {for , := range {if := .AppendObject(); != nil {return } }returnnil}// ObjectMarshalerPtr is a constraint that specifies that the given type// implements zapcore.ObjectMarshaler on a pointer receiver.typeObjectMarshalerPtr[ any] interface { *zapcore.ObjectMarshaler}// 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 [ any, ObjectMarshalerPtr[]]( string, []) Field {returnArray(, objectValues[, ]())}typeobjectValues[ any, ObjectMarshalerPtr[]] []func ( objectValues[, ]) ( zapcore.ArrayEncoder) error {for := range {// It is necessary for us to explicitly reference the "P" type. // We cannot simply pass "&os[i]" to AppendObject because its type // is "*T", which the type system does not consider as // implementing ObjectMarshaler. // Only the type "P" satisfies ObjectMarshaler, which we have // to convert "*T" to explicitly.var = &[]if := .AppendObject(); != nil {return } }returnnil}// Strings constructs a field that carries a slice of strings.func ( string, []string) Field {returnArray(, stringArray())}// 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 [ fmt.Stringer]( string, []) Field {returnArray(, stringers[]())}typestringers[ fmt.Stringer] []func ( stringers[]) ( zapcore.ArrayEncoder) error {for , := range { .AppendString(.String()) }returnnil}// Times constructs a field that carries a slice of time.Times.func ( string, []time.Time) Field {returnArray(, times())}// Uints constructs a field that carries a slice of unsigned integers.func ( string, []uint) Field {returnArray(, uints())}// Uint64s constructs a field that carries a slice of unsigned integers.func ( string, []uint64) Field {returnArray(, uint64s())}// Uint32s constructs a field that carries a slice of unsigned integers.func ( string, []uint32) Field {returnArray(, uint32s())}// Uint16s constructs a field that carries a slice of unsigned integers.func ( string, []uint16) Field {returnArray(, uint16s())}// Uint8s constructs a field that carries a slice of unsigned integers.func ( string, []uint8) Field {returnArray(, uint8s())}// Uintptrs constructs a field that carries a slice of pointer addresses.func ( string, []uintptr) Field {returnArray(, uintptrs())}// Errors constructs a field that carries a slice of errors.func ( string, []error) Field {returnArray(, errArray())}typebools []boolfunc ( bools) ( zapcore.ArrayEncoder) error {for := range { .AppendBool([]) }returnnil}typebyteStringsArray [][]bytefunc ( byteStringsArray) ( zapcore.ArrayEncoder) error {for := range { .AppendByteString([]) }returnnil}typecomplex128s []complex128func ( complex128s) ( zapcore.ArrayEncoder) error {for := range { .AppendComplex128([]) }returnnil}typecomplex64s []complex64func ( complex64s) ( zapcore.ArrayEncoder) error {for := range { .AppendComplex64([]) }returnnil}typedurations []time.Durationfunc ( durations) ( zapcore.ArrayEncoder) error {for := range { .AppendDuration([]) }returnnil}typefloat64s []float64func ( float64s) ( zapcore.ArrayEncoder) error {for := range { .AppendFloat64([]) }returnnil}typefloat32s []float32func ( float32s) ( zapcore.ArrayEncoder) error {for := range { .AppendFloat32([]) }returnnil}typeints []intfunc ( ints) ( zapcore.ArrayEncoder) error {for := range { .AppendInt([]) }returnnil}typeint64s []int64func ( int64s) ( zapcore.ArrayEncoder) error {for := range { .AppendInt64([]) }returnnil}typeint32s []int32func ( int32s) ( zapcore.ArrayEncoder) error {for := range { .AppendInt32([]) }returnnil}typeint16s []int16func ( int16s) ( zapcore.ArrayEncoder) error {for := range { .AppendInt16([]) }returnnil}typeint8s []int8func ( int8s) ( zapcore.ArrayEncoder) error {for := range { .AppendInt8([]) }returnnil}typestringArray []stringfunc ( stringArray) ( zapcore.ArrayEncoder) error {for := range { .AppendString([]) }returnnil}typetimes []time.Timefunc ( times) ( zapcore.ArrayEncoder) error {for := range { .AppendTime([]) }returnnil}typeuints []uintfunc ( uints) ( zapcore.ArrayEncoder) error {for := range { .AppendUint([]) }returnnil}typeuint64s []uint64func ( uint64s) ( zapcore.ArrayEncoder) error {for := range { .AppendUint64([]) }returnnil}typeuint32s []uint32func ( uint32s) ( zapcore.ArrayEncoder) error {for := range { .AppendUint32([]) }returnnil}typeuint16s []uint16func ( uint16s) ( zapcore.ArrayEncoder) error {for := range { .AppendUint16([]) }returnnil}typeuint8s []uint8func ( uint8s) ( zapcore.ArrayEncoder) error {for := range { .AppendUint8([]) }returnnil}typeuintptrs []uintptrfunc ( uintptrs) ( zapcore.ArrayEncoder) error {for := range { .AppendUintptr([]) }returnnil}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.