Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(args ...interface{})
- func DebugFiled(msg string, fields ...Field)
- func Debugf(fmt string, args ...interface{})
- func Enable(level types.Level) bool
- func EpochMillisTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
- func EpochNanosTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
- func EpochTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
- func Error(args ...interface{})
- func ErrorFiled(msg string, fields ...Field)
- func Errorf(fmt string, args ...interface{})
- func Fatal(args ...interface{})
- func FatalFiled(msg string, fields ...Field)
- func Fatalf(fmt string, args ...interface{})
- func FullNameEncoder(loggerName string, enc PrimitiveArrayEncoder)
- func GetConstructor(name string) types.LoggerConstructor
- func GetLevel() types.Level
- func GetLogger(name string) types.Logger
- func GetRaw() interface{}
- func ISO8601TimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
- func Info(args ...interface{})
- func InfoFiled(msg string, fields ...Field)
- func Infof(fmt string, args ...interface{})
- func MillisDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
- func NanosDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
- func RFC3339NanoTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
- func RFC3339TimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
- func RegisterConstructor(name string, f types.LoggerConstructor)
- func SecondsDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
- func SetDurationEncoder(de DurationEncoder)
- func SetDurationEncoderByName(name string) error
- func SetLevel(level types.Level)
- func SetLogger(logger types.Logger)
- func SetStackPrintState(b bool)
- func SetTimeEncoder(te TimeEncoder)
- func SetTimeEncoderByName(name string) error
- func StringDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
- func Warn(args ...interface{})
- func WarnFiled(msg string, fields ...Field)
- func Warnf(fmt string, args ...interface{})
- type ArrayEncoder
- type ArrayMarshaler
- type ArrayMarshalerFunc
- type DurationEncoder
- type Encoder
- type Field
- func Any(key string, value interface{}) Field
- func Array(key string, val ArrayMarshaler) Field
- func Binary(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Boolp(key string, val *bool) Field
- func Bools(key string, bs []bool) Field
- func ByteString(key string, val []byte) Field
- func ByteStrings(key string, bss [][]byte) Field
- func Complex128(key string, val complex128) Field
- func Complex128p(key string, val *complex128) Field
- func Complex128s(key string, nums []complex128) Field
- func Complex64(key string, val complex64) Field
- func Complex64p(key string, val *complex64) Field
- func Complex64s(key string, nums []complex64) Field
- func Context(ctx context.Context) Field
- func Duration(key string, val time.Duration) Field
- func Durationp(key string, val *time.Duration) Field
- func Durations(key string, ds []time.Duration) Field
- func Err(err error) Field
- func Errors(key string, errs []error) Field
- func Float32(key string, val float32) Field
- func Float32p(key string, val *float32) Field
- func Float32s(key string, nums []float32) Field
- func Float64(key string, val float64) Field
- func Float64p(key string, val *float64) Field
- func Float64s(key string, nums []float64) Field
- func Inline(val ObjectMarshaler) Field
- func Int(key string, val int) Field
- func Int16(key string, val int16) Field
- func Int16p(key string, val *int16) Field
- func Int16s(key string, nums []int16) Field
- func Int32(key string, val int32) Field
- func Int32p(key string, val *int32) Field
- func Int32s(key string, nums []int32) Field
- func Int64(key string, val int64) Field
- func Int64p(key string, val *int64) Field
- func Int64s(key string, nums []int64) Field
- func Int8(key string, val int8) Field
- func Int8p(key string, val *int8) Field
- func Int8s(key string, nums []int8) Field
- func Intp(key string, val *int) Field
- func Ints(key string, nums []int) Field
- func NamedErr(key string, err error) Field
- func Namespace(key string) Field
- func Object(key string, val ObjectMarshaler) Field
- func Reflect(key string, val interface{}) Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Stringp(key string, val *string) Field
- func Strings(key string, ss []string) Field
- func Time(key string, val time.Time) Field
- func Timep(key string, val *time.Time) Field
- func Times(key string, ts []time.Time) Field
- func Uint(key string, val uint) Field
- func Uint16(key string, val uint16) Field
- func Uint16p(key string, val *uint16) Field
- func Uint16s(key string, nums []uint16) Field
- func Uint32(key string, val uint32) Field
- func Uint32p(key string, val *uint32) Field
- func Uint32s(key string, nums []uint32) Field
- func Uint64(key string, val uint64) Field
- func Uint64p(key string, val *uint64) Field
- func Uint64s(key string, nums []uint64) Field
- func Uint8(key string, val uint8) Field
- func Uint8p(key string, val *uint8) Field
- func Uint8s(key string, nums []uint8) Field
- func Uintp(key string, val *uint) Field
- func Uintptr(key string, val uintptr) Field
- func Uintptrp(key string, val *uintptr) Field
- func Uintptrs(key string, us []uintptr) Field
- func Uints(key string, nums []uint) Field
- type FieldType
- type NameEncoder
- type ObjectEncoder
- type ObjectMarshaler
- type ObjectMarshalerFunc
- type PrimitiveArrayEncoder
- type ReflectedEncoder
- type StdLogger
- func (l *StdLogger) Debug(args ...interface{})
- func (l *StdLogger) Debugf(format string, args ...interface{})
- func (l *StdLogger) Debugw(msg string, kvs ...interface{})
- func (l *StdLogger) Enable(level types.Level) bool
- func (l *StdLogger) Error(args ...interface{})
- func (l *StdLogger) Errorf(format string, args ...interface{})
- func (l *StdLogger) Errorw(msg string, kvs ...interface{})
- func (l *StdLogger) Fatal(args ...interface{})
- func (l *StdLogger) Fatalf(format string, args ...interface{})
- func (l *StdLogger) Fatalw(msg string, kvs ...interface{})
- func (l *StdLogger) GetLevel() types.Level
- func (l *StdLogger) GetRaw() interface{}
- func (l *StdLogger) Info(args ...interface{})
- func (l *StdLogger) Infof(format string, args ...interface{})
- func (l *StdLogger) Infow(msg string, kvs ...interface{})
- func (l *StdLogger) OpenMsgFormat()
- func (l *StdLogger) SetLevel(level types.Level)
- func (l *StdLogger) Warn(args ...interface{})
- func (l *StdLogger) Warnf(format string, args ...interface{})
- func (l *StdLogger) Warnw(msg string, kvs ...interface{})
- type TimeEncoder
Constants ¶
const DefaultLineEnding = "\n"
DefaultLineEnding defines the default line ending when writing logs. Alternate line endings specified in EncoderConfig can override this behavior.
const OmitKey = ""
OmitKey defines the key to use when callers want to remove a key from log output.
Variables ¶
var (
// Get retrieves a buffer from the pool, creating one if necessary.
Get = _pool.Get
)
Functions ¶
func DebugFiled ¶ added in v0.1.3
func EpochMillisTimeEncoder ¶ added in v0.1.3
func EpochMillisTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
EpochMillisTimeEncoder serializes a time.Time to a floating-point number of milliseconds since the Unix epoch.
func EpochNanosTimeEncoder ¶ added in v0.1.3
func EpochNanosTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
EpochNanosTimeEncoder serializes a time.Time to an integer number of nanoseconds since the Unix epoch.
func EpochTimeEncoder ¶ added in v0.1.3
func EpochTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
EpochTimeEncoder serializes a time.Time to a floating-point number of seconds since the Unix epoch.
func ErrorFiled ¶ added in v0.1.3
func FatalFiled ¶ added in v0.1.3
func FullNameEncoder ¶ added in v0.1.3
func FullNameEncoder(loggerName string, enc PrimitiveArrayEncoder)
FullNameEncoder serializes the logger name as-is.
func GetConstructor ¶ added in v0.1.1
func GetConstructor(name string) types.LoggerConstructor
func ISO8601TimeEncoder ¶ added in v0.1.3
func ISO8601TimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
ISO8601TimeEncoder serializes a time.Time to an ISO8601-formatted string with millisecond precision.
If enc supports AppendTimeLayout(t time.Time,layout string), it's used instead of appending a pre-formatted string value.
func MillisDurationEncoder ¶ added in v0.1.3
func MillisDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
MillisDurationEncoder serializes a time.Duration to an integer number of milliseconds elapsed.
func NanosDurationEncoder ¶ added in v0.1.3
func NanosDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
NanosDurationEncoder serializes a time.Duration to an integer number of nanoseconds elapsed.
func RFC3339NanoTimeEncoder ¶ added in v0.1.3
func RFC3339NanoTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
RFC3339NanoTimeEncoder serializes a time.Time to an RFC3339-formatted string with nanosecond precision.
If enc supports AppendTimeLayout(t time.Time,layout string), it's used instead of appending a pre-formatted string value.
func RFC3339TimeEncoder ¶ added in v0.1.3
func RFC3339TimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
RFC3339TimeEncoder serializes a time.Time to an RFC3339-formatted string.
If enc supports AppendTimeLayout(t time.Time,layout string), it's used instead of appending a pre-formatted string value.
func RegisterConstructor ¶ added in v0.1.1
func RegisterConstructor(name string, f types.LoggerConstructor)
func SecondsDurationEncoder ¶ added in v0.1.3
func SecondsDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
SecondsDurationEncoder serializes a time.Duration to a floating-point number of seconds elapsed.
func SetDurationEncoder ¶ added in v0.1.3
func SetDurationEncoder(de DurationEncoder)
func SetDurationEncoderByName ¶ added in v0.1.3
func SetStackPrintState ¶ added in v0.1.3
func SetStackPrintState(b bool)
func SetTimeEncoder ¶ added in v0.1.3
func SetTimeEncoder(te TimeEncoder)
func SetTimeEncoderByName ¶ added in v0.1.3
func StringDurationEncoder ¶ added in v0.1.3
func StringDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
StringDurationEncoder serializes a time.Duration using its built-in String method.
Types ¶
type ArrayEncoder ¶ added in v0.1.3
type ArrayEncoder interface { // Built-in types. PrimitiveArrayEncoder // Time-related types. AppendDuration(time.Duration) AppendTime(time.Time) // Logging-specific marshalers. AppendArray(ArrayMarshaler) error AppendObject(ObjectMarshaler) error // AppendReflected uses reflection to serialize arbitrary objects, so it's // slow and allocation-heavy. AppendReflected(value interface{}) error }
ArrayEncoder is a strongly-typed, encoding-agnostic interface for adding array-like objects to the logging context. Of note, it supports mixed-type arrays even though they aren't typical in Go. Like slices, ArrayEncoders aren't safe for concurrent use (though typical use shouldn't require locks).
type ArrayMarshaler ¶ added in v0.1.3
type ArrayMarshaler interface {
MarshalLogArray(ArrayEncoder) error
}
ArrayMarshaler allows user-defined types to efficiently add themselves to the logging context, and to selectively omit information which shouldn't be included in logs (e.g., passwords).
Note: ArrayMarshaler is only used when zap.Array is used or when passed directly to zap.Any. It is not used when reflection-based encoding is used.
type ArrayMarshalerFunc ¶ added in v0.1.3
type ArrayMarshalerFunc func(ArrayEncoder) error
ArrayMarshalerFunc is a type adapter that turns a function into an ArrayMarshaler.
func (ArrayMarshalerFunc) MarshalLogArray ¶ added in v0.1.3
func (f ArrayMarshalerFunc) MarshalLogArray(enc ArrayEncoder) error
MarshalLogArray calls the underlying function.
type DurationEncoder ¶ added in v0.1.3
type DurationEncoder func(time.Duration, PrimitiveArrayEncoder)
A DurationEncoder serializes a time.Duration to a primitive type.
func (*DurationEncoder) UnmarshalText ¶ added in v0.1.3
func (e *DurationEncoder) UnmarshalText(text []byte) error
UnmarshalText unmarshals text to a DurationEncoder. "string" is unmarshaled to StringDurationEncoder, and anything else is unmarshaled to NanosDurationEncoder.
type Encoder ¶ added in v0.1.3
type Encoder interface { ObjectEncoder // Clone copies the encoder, ensuring that adding fields to the copy doesn't // affect the original. Clone() Encoder // EncodeEntry encodes an entry and fields, along with any accumulated // context, into a byte buffer and returns it. Any fields that are empty, // including fields on the `Entry` type, should be omitted. Encode([]Field) (*buffer.Buffer, error) }
Encoder is a format-agnostic interface for all log entry marshalers. Since log encoders don't need to support the same wide range of use cases as general-purpose marshalers, it's possible to make them faster and lower-allocation.
Implementations of the ObjectEncoder interface's methods can, of course, freely modify the receiver. However, the Clone and EncodeEntry methods will be called concurrently and shouldn't modify the receiver.
func NewJsonEncoder ¶ added in v0.1.3
func NewJsonEncoder() Encoder
type Field ¶ added in v0.1.3
A Field is a marshaling operation used to add a key-value pair to a logger's context. Most fields are lazily marshaled, so it's inexpensive to add fields to disabled debug-level log statements.
func Any ¶ added in v0.1.3
Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.
Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between them. To minimize surprises, []byte values are treated as binary blobs, byte values are treated as uint8, and runes are always treated as integers.
func Array ¶ added in v0.1.3
func Array(key string, val ArrayMarshaler) Field
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 Binary ¶ added in v0.1.3
Binary constructs a field that carries an opaque binary blob.
Binary data is serialized in an encoding-appropriate format. For example, zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.
func Boolp ¶ added in v0.1.3
Boolp constructs a field that carries a *bool. The returned Field will safely and explicitly represent `nil` when appropriate.
func ByteString ¶ added in v0.1.3
ByteString constructs a field that carries UTF-8 encoded text as a []byte. To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.
func ByteStrings ¶ added in v0.1.3
ByteStrings constructs a field that carries a slice of []byte, each of which must be UTF-8 encoded text.
func Complex128 ¶ added in v0.1.3
func Complex128(key string, val complex128) Field
Complex128 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex128 to interface{}).
func Complex128p ¶ added in v0.1.3
func Complex128p(key string, val *complex128) Field
Complex128p constructs a field that carries a *complex128. The returned Field will safely and explicitly represent `nil` when appropriate.
func Complex128s ¶ added in v0.1.3
func Complex128s(key string, nums []complex128) Field
Complex128s constructs a field that carries a slice of complex numbers.
func Complex64 ¶ added in v0.1.3
Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).
func Complex64p ¶ added in v0.1.3
Complex64p constructs a field that carries a *complex64. The returned Field will safely and explicitly represent `nil` when appropriate.
func Complex64s ¶ added in v0.1.3
Complex64s constructs a field that carries a slice of complex numbers.
func Context ¶ added in v0.1.3
Context constructs a Field carries a context. Context which with trace span will have their trace ID and span ID stored under traceID and spanID.
func Duration ¶ added in v0.1.3
Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.
func Durationp ¶ added in v0.1.3
Durationp constructs a field that carries a *time.Duration. The returned Field will safely and explicitly represent `nil` when appropriate.
func Durations ¶ added in v0.1.3
Durations constructs a field that carries a slice of time.Durations.
func Float32 ¶ added in v0.1.3
Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func Float32p ¶ added in v0.1.3
Float32p constructs a field that carries a *float32. The returned Field will safely and explicitly represent `nil` when appropriate.
func Float64 ¶ added in v0.1.3
Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.
func Float64p ¶ added in v0.1.3
Float64p constructs a field that carries a *float64. The returned Field will safely and explicitly represent `nil` when appropriate.
func Inline ¶ added in v0.1.3
func Inline(val ObjectMarshaler) Field
Inline constructs a Field that is similar to Object, but it will add the elements of the provided ObjectMarshaler to the current namespace.
func Int16p ¶ added in v0.1.3
Int16p constructs a field that carries a *int16. The returned Field will safely and explicitly represent `nil` when appropriate.
func Int32p ¶ added in v0.1.3
Int32p constructs a field that carries a *int32. The returned Field will safely and explicitly represent `nil` when appropriate.
func Int64p ¶ added in v0.1.3
Int64p constructs a field that carries a *int64. The returned Field will safely and explicitly represent `nil` when appropriate.
func Int8p ¶ added in v0.1.3
Int8p constructs a field that carries a *int8. The returned Field will safely and explicitly represent `nil` when appropriate.
func Intp ¶ added in v0.1.3
Intp constructs a field that carries a *int. The returned Field will safely and explicitly represent `nil` when appropriate.
func NamedErr ¶ added in v0.1.3
NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op.
For the common case in which the key is simply "error", the Error function is shorter and less repetitive.
func Namespace ¶ added in v0.1.3
Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.
This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.
func Object ¶ added in v0.1.3
func Object(key string, val ObjectMarshaler) Field
Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.
func Reflect ¶ added in v0.1.3
Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.
func Stringer ¶ added in v0.1.3
Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.
func Stringp ¶ added in v0.1.3
Stringp constructs a field that carries a *string. The returned Field will safely and explicitly represent `nil` when appropriate.
func Time ¶ added in v0.1.3
Time constructs a Field with the given key and value. The encoder controls how the time is serialized.
func Timep ¶ added in v0.1.3
Timep constructs a field that carries a *time.Time. The returned Field will safely and explicitly represent `nil` when appropriate.
func Uint16p ¶ added in v0.1.3
Uint16p constructs a field that carries a *uint16. The returned Field will safely and explicitly represent `nil` when appropriate.
func Uint16s ¶ added in v0.1.3
Uint16s constructs a field that carries a slice of unsigned integers.
func Uint32p ¶ added in v0.1.3
Uint32p constructs a field that carries a *uint32. The returned Field will safely and explicitly represent `nil` when appropriate.
func Uint32s ¶ added in v0.1.3
Uint32s constructs a field that carries a slice of unsigned integers.
func Uint64p ¶ added in v0.1.3
Uint64p constructs a field that carries a *uint64. The returned Field will safely and explicitly represent `nil` when appropriate.
func Uint64s ¶ added in v0.1.3
Uint64s constructs a field that carries a slice of unsigned integers.
func Uint8p ¶ added in v0.1.3
Uint8p constructs a field that carries a *uint8. The returned Field will safely and explicitly represent `nil` when appropriate.
func Uintp ¶ added in v0.1.3
Uintp constructs a field that carries a *uint. The returned Field will safely and explicitly represent `nil` when appropriate.
func Uintptrp ¶ added in v0.1.3
Uintptrp constructs a field that carries a *uintptr. The returned Field will safely and explicitly represent `nil` when appropriate.
func Uintptrs ¶ added in v0.1.3
Uintptrs constructs a field that carries a slice of pointer addresses.
func (Field) AddTo ¶ added in v0.1.3
func (f Field) AddTo(enc ObjectEncoder)
AddTo exports a field through the ObjectEncoder interface. It's primarily useful to library authors, and shouldn't be necessary in most applications.
type FieldType ¶ added in v0.1.3
type FieldType uint8
A FieldType indicates which member of the Field union struct should be used and how it should be serialized.
const ( // UnknownType is the default field type. Attempting to add it to an encoder will panic. UnknownType FieldType = iota // ArrayMarshalerType indicates that the field carries an ArrayMarshaler. ArrayMarshalerType // ObjectMarshalerType indicates that the field carries an ObjectMarshaler. ObjectMarshalerType // BinaryType indicates that the field carries an opaque binary blob. BinaryType // BoolType indicates that the field carries a bool. BoolType // ByteStringType indicates that the field carries UTF-8 encoded bytes. ByteStringType // Complex128Type indicates that the field carries a complex128. Complex128Type // Complex64Type indicates that the field carries a complex128. Complex64Type // DurationType indicates that the field carries a time.Duration. DurationType // Float64Type indicates that the field carries a float64. Float64Type // Float32Type indicates that the field carries a float32. Float32Type // Int64Type indicates that the field carries an int64. Int64Type // Int32Type indicates that the field carries an int32. Int32Type // Int16Type indicates that the field carries an int16. Int16Type // Int8Type indicates that the field carries an int8. Int8Type // StringType indicates that the field carries a string. StringType // TimeType indicates that the field carries a time.Time that is // representable by a UnixNano() stored as an int64. TimeType // TimeFullType indicates that the field carries a time.Time stored as-is. TimeFullType // Uint64Type indicates that the field carries a uint64. Uint64Type // Uint32Type indicates that the field carries a uint32. Uint32Type // Uint16Type indicates that the field carries a uint16. Uint16Type // Uint8Type indicates that the field carries a uint8. Uint8Type // UintptrType indicates that the field carries a uintptr. UintptrType // ReflectType indicates that the field carries an interface{}, which should // be serialized using reflection. ReflectType // NamespaceType signals the beginning of an isolated namespace. All // subsequent fields should be added to the new namespace. NamespaceType // StringerType indicates that the field carries a fmt.Stringer. StringerType // ErrorType indicates that the field carries an error. ErrorType // SkipType indicates that the field is a no-op. SkipType // CtxType indicates that the field is a context. CtxType // InlineMarshalerType indicates that the field carries an ObjectMarshaler // that should be inlined. InlineMarshalerType )
type NameEncoder ¶ added in v0.1.3
type NameEncoder func(string, PrimitiveArrayEncoder)
A NameEncoder serializes a period-separated logger name to a primitive type.
func (*NameEncoder) UnmarshalText ¶ added in v0.1.3
func (e *NameEncoder) UnmarshalText(text []byte) error
UnmarshalText unmarshals text to a NameEncoder. Currently, everything is unmarshaled to FullNameEncoder.
type ObjectEncoder ¶ added in v0.1.3
type ObjectEncoder interface { // Logging-specific marshalers. AddArray(key string, marshaler ArrayMarshaler) error AddObject(key string, marshaler ObjectMarshaler) error // Built-in types. AddBinary(key string, value []byte) // for arbitrary bytes AddByteString(key string, value []byte) // for UTF-8 encoded bytes AddBool(key string, value bool) AddComplex128(key string, value complex128) AddComplex64(key string, value complex64) AddDuration(key string, value time.Duration) AddFloat64(key string, value float64) AddFloat32(key string, value float32) AddInt(key string, value int) AddInt64(key string, value int64) AddInt32(key string, value int32) AddInt16(key string, value int16) AddInt8(key string, value int8) AddString(key, value string) AddTime(key string, value time.Time) AddUint(key string, value uint) AddUint64(key string, value uint64) AddUint32(key string, value uint32) AddUint16(key string, value uint16) AddUint8(key string, value uint8) AddUintptr(key string, value uintptr) // AddReflected uses reflection to serialize arbitrary objects, so it can be // slow and allocation-heavy. AddReflected(key string, value interface{}) error // OpenNamespace opens an isolated namespace where all subsequent fields will // be added. Applications can use namespaces to prevent key collisions when // injecting loggers into sub-components or third-party libraries. OpenNamespace(key string) SetDurationEncoder(de DurationEncoder) SetTimeEncoder(te TimeEncoder) }
ObjectEncoder is a strongly-typed, encoding-agnostic interface for adding a map- or struct-like object to the logging context. Like maps, ObjectEncoders aren't safe for concurrent use (though typical use shouldn't require locks).
type ObjectMarshaler ¶ added in v0.1.3
type ObjectMarshaler interface {
MarshalLogObject(ObjectEncoder) error
}
ObjectMarshaler allows user-defined types to efficiently add themselves to the logging context, and to selectively omit information which shouldn't be included in logs (e.g., passwords).
Note: ObjectMarshaler is only used when zap.Object is used or when passed directly to zap.Any. It is not used when reflection-based encoding is used.
type ObjectMarshalerFunc ¶ added in v0.1.3
type ObjectMarshalerFunc func(ObjectEncoder) error
ObjectMarshalerFunc is a type adapter that turns a function into an ObjectMarshaler.
func (ObjectMarshalerFunc) MarshalLogObject ¶ added in v0.1.3
func (f ObjectMarshalerFunc) MarshalLogObject(enc ObjectEncoder) error
MarshalLogObject calls the underlying function.
type PrimitiveArrayEncoder ¶ added in v0.1.3
type PrimitiveArrayEncoder interface { // Built-in types. AppendBool(bool) AppendByteString([]byte) // for UTF-8 encoded bytes AppendComplex128(complex128) AppendComplex64(complex64) AppendFloat64(float64) AppendFloat32(float32) AppendInt(int) AppendInt64(int64) AppendInt32(int32) AppendInt16(int16) AppendInt8(int8) AppendString(string) AppendUint(uint) AppendUint64(uint64) AppendUint32(uint32) AppendUint16(uint16) AppendUint8(uint8) AppendUintptr(uintptr) }
PrimitiveArrayEncoder is the subset of the ArrayEncoder interface that deals only in Go's built-in types. It's included only so that Duration- and TimeEncoders cannot trigger infinite recursion.
type ReflectedEncoder ¶ added in v0.1.3
type ReflectedEncoder interface { // Encode encodes and writes to the underlying data stream. Encode(interface{}) error }
ReflectedEncoder serializes log fields that can't be serialized with Zap's JSON encoder. These have the ReflectType field type. Use EncoderConfig.NewReflectedEncoder to set this.
type StdLogger ¶
type StdLogger struct {
// contains filtered or unexported fields
}
func (*StdLogger) OpenMsgFormat ¶ added in v0.1.3
func (l *StdLogger) OpenMsgFormat()
type TimeEncoder ¶ added in v0.1.3
type TimeEncoder func(time.Time, PrimitiveArrayEncoder)
A TimeEncoder serializes a time.Time to a primitive type.
func TimeEncoderOfLayout ¶ added in v0.1.3
func TimeEncoderOfLayout(layout string) TimeEncoder
TimeEncoderOfLayout returns TimeEncoder which serializes a time.Time using given layout.
func (*TimeEncoder) UnmarshalJSON ¶ added in v0.1.3
func (e *TimeEncoder) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals JSON to a TimeEncoder as same way UnmarshalYAML does.
func (*TimeEncoder) UnmarshalText ¶ added in v0.1.3
func (e *TimeEncoder) UnmarshalText(text []byte) error
UnmarshalText unmarshals text to a TimeEncoder. "rfc3339nano" and "RFC3339Nano" are unmarshaled to RFC3339NanoTimeEncoder. "rfc3339" and "RFC3339" are unmarshaled to RFC3339TimeEncoder. "iso8601" and "ISO8601" are unmarshaled to ISO8601TimeEncoder. "millis" is unmarshaled to EpochMillisTimeEncoder. "nanos" is unmarshaled to EpochNanosEncoder. Anything else is unmarshaled to EpochTimeEncoder.
func (*TimeEncoder) UnmarshalYAML ¶ added in v0.1.3
func (e *TimeEncoder) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML unmarshals YAML to a TimeEncoder. If value is an object with a "layout" field, it will be unmarshaled to TimeEncoder with given layout.
timeEncoder: layout: 06/01/02 03:04pm
If value is string, it uses UnmarshalText.
timeEncoder: iso8601