log

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLineEnding = "\n"

DefaultLineEnding defines the default line ending when writing logs. Alternate line endings specified in EncoderConfig can override this behavior.

View Source
const OmitKey = ""

OmitKey defines the key to use when callers want to remove a key from log output.

Variables

View Source
var (

	// Get retrieves a buffer from the pool, creating one if necessary.
	Get = _pool.Get
)

Functions

func Debug

func Debug(args ...interface{})

Debug is debug level

func DebugFiled added in v0.1.3

func DebugFiled(msg string, fields ...Field)

func Debugf

func Debugf(fmt string, args ...interface{})

Debugf is format debug level

func Enable

func Enable(level types.Level) bool

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 Error

func Error(args ...interface{})

Error is error level

func ErrorFiled added in v0.1.3

func ErrorFiled(msg string, fields ...Field)

func Errorf

func Errorf(fmt string, args ...interface{})

Errorf is format error level

func Fatal

func Fatal(args ...interface{})

Error is fault level

func FatalFiled added in v0.1.3

func FatalFiled(msg string, fields ...Field)

func Fatalf

func Fatalf(fmt string, args ...interface{})

Fatalf is format fatal level

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 GetLevel

func GetLevel() types.Level

func GetLogger added in v0.1.1

func GetLogger(name string) types.Logger

func GetRaw

func GetRaw() interface{}

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 Info

func Info(args ...interface{})

Info is info level

func InfoFiled added in v0.1.3

func InfoFiled(msg string, fields ...Field)

func Infof

func Infof(fmt string, args ...interface{})

Infof is format info level

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 SetDurationEncoderByName(name string) error

func SetLevel

func SetLevel(level types.Level)

func SetLogger

func SetLogger(logger types.Logger)

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 SetTimeEncoderByName(name string) error

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.

func Warn

func Warn(args ...interface{})

Warn is warning level

func WarnFiled added in v0.1.3

func WarnFiled(msg string, fields ...Field)

func Warnf

func Warnf(fmt string, args ...interface{})

Warnf is format warning level

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

type Field struct {
	Key       string
	Type      FieldType
	Integer   int64
	String    string
	Interface interface{}
}

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

func Any(key string, value interface{}) Field

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

func Binary(key string, val []byte) Field

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 Bool added in v0.1.3

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func Boolp added in v0.1.3

func Boolp(key string, val *bool) Field

Boolp constructs a field that carries a *bool. The returned Field will safely and explicitly represent `nil` when appropriate.

func Bools added in v0.1.3

func Bools(key string, bs []bool) Field

Bools constructs a field that carries a slice of bools.

func ByteString added in v0.1.3

func ByteString(key string, val []byte) Field

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

func ByteStrings(key string, bss [][]byte) Field

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

func Complex64(key string, val complex64) Field

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

func Complex64p(key string, val *complex64) Field

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

func Complex64s(key string, nums []complex64) Field

Complex64s constructs a field that carries a slice of complex numbers.

func Context added in v0.1.3

func Context(ctx context.Context) Field

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

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

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

func Durationp(key string, val *time.Duration) Field

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

func Durations(key string, ds []time.Duration) Field

Durations constructs a field that carries a slice of time.Durations.

func Err added in v0.1.3

func Err(err error) Field

Error is shorthand for the common idiom NamedErr("error", err).

func Errors added in v0.1.3

func Errors(key string, errs []error) Field

Errors constructs a field that carries a slice of errors.

func Float32 added in v0.1.3

func Float32(key string, val float32) Field

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

func Float32p(key string, val *float32) Field

Float32p constructs a field that carries a *float32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Float32s added in v0.1.3

func Float32s(key string, nums []float32) Field

Float32s constructs a field that carries a slice of floats.

func Float64 added in v0.1.3

func Float64(key string, val float64) Field

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

func Float64p(key string, val *float64) Field

Float64p constructs a field that carries a *float64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Float64s added in v0.1.3

func Float64s(key string, nums []float64) Field

Float64s constructs a field that carries a slice of floats.

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 Int added in v0.1.3

func Int(key string, val int) Field

Int constructs a field with the given key and value.

func Int16 added in v0.1.3

func Int16(key string, val int16) Field

Int16 constructs a field with the given key and value.

func Int16p added in v0.1.3

func Int16p(key string, val *int16) Field

Int16p constructs a field that carries a *int16. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int16s added in v0.1.3

func Int16s(key string, nums []int16) Field

Int16s constructs a field that carries a slice of integers.

func Int32 added in v0.1.3

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int32p added in v0.1.3

func Int32p(key string, val *int32) Field

Int32p constructs a field that carries a *int32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int32s added in v0.1.3

func Int32s(key string, nums []int32) Field

Int32s constructs a field that carries a slice of integers.

func Int64 added in v0.1.3

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func Int64p added in v0.1.3

func Int64p(key string, val *int64) Field

Int64p constructs a field that carries a *int64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int64s added in v0.1.3

func Int64s(key string, nums []int64) Field

Int64s constructs a field that carries a slice of integers.

func Int8 added in v0.1.3

func Int8(key string, val int8) Field

Int8 constructs a field with the given key and value.

func Int8p added in v0.1.3

func Int8p(key string, val *int8) Field

Int8p constructs a field that carries a *int8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int8s added in v0.1.3

func Int8s(key string, nums []int8) Field

Int8s constructs a field that carries a slice of integers.

func Intp added in v0.1.3

func Intp(key string, val *int) Field

Intp constructs a field that carries a *int. The returned Field will safely and explicitly represent `nil` when appropriate.

func Ints added in v0.1.3

func Ints(key string, nums []int) Field

Ints constructs a field that carries a slice of integers.

func NamedErr added in v0.1.3

func NamedErr(key string, err error) Field

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

func Namespace(key string) Field

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

func Reflect(key string, val interface{}) Field

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 String added in v0.1.3

func String(key string, val string) Field

String constructs a field with the given key and value.

func Stringer added in v0.1.3

func Stringer(key string, val fmt.Stringer) Field

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

func Stringp(key string, val *string) Field

Stringp constructs a field that carries a *string. The returned Field will safely and explicitly represent `nil` when appropriate.

func Strings added in v0.1.3

func Strings(key string, ss []string) Field

Strings constructs a field that carries a slice of strings.

func Time added in v0.1.3

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

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

func Timep(key string, val *time.Time) Field

Timep constructs a field that carries a *time.Time. The returned Field will safely and explicitly represent `nil` when appropriate.

func Times added in v0.1.3

func Times(key string, ts []time.Time) Field

Times constructs a field that carries a slice of time.Times.

func Uint added in v0.1.3

func Uint(key string, val uint) Field

Uint constructs a field with the given key and value.

func Uint16 added in v0.1.3

func Uint16(key string, val uint16) Field

Uint16 constructs a field with the given key and value.

func Uint16p added in v0.1.3

func Uint16p(key string, val *uint16) Field

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

func Uint16s(key string, nums []uint16) Field

Uint16s constructs a field that carries a slice of unsigned integers.

func Uint32 added in v0.1.3

func Uint32(key string, val uint32) Field

Uint32 constructs a field with the given key and value.

func Uint32p added in v0.1.3

func Uint32p(key string, val *uint32) Field

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

func Uint32s(key string, nums []uint32) Field

Uint32s constructs a field that carries a slice of unsigned integers.

func Uint64 added in v0.1.3

func Uint64(key string, val uint64) Field

Uint64 constructs a field with the given key and value.

func Uint64p added in v0.1.3

func Uint64p(key string, val *uint64) Field

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

func Uint64s(key string, nums []uint64) Field

Uint64s constructs a field that carries a slice of unsigned integers.

func Uint8 added in v0.1.3

func Uint8(key string, val uint8) Field

Uint8 constructs a field with the given key and value.

func Uint8p added in v0.1.3

func Uint8p(key string, val *uint8) Field

Uint8p constructs a field that carries a *uint8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint8s added in v0.1.3

func Uint8s(key string, nums []uint8) Field

Uint8s constructs a field that carries a slice of unsigned integers.

func Uintp added in v0.1.3

func Uintp(key string, val *uint) Field

Uintp constructs a field that carries a *uint. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uintptr added in v0.1.3

func Uintptr(key string, val uintptr) Field

Uintptr constructs a field with the given key and value.

func Uintptrp added in v0.1.3

func Uintptrp(key string, val *uintptr) Field

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

func Uintptrs(key string, us []uintptr) Field

Uintptrs constructs a field that carries a slice of pointer addresses.

func Uints added in v0.1.3

func Uints(key string, nums []uint) Field

Uints constructs a field that carries a slice of unsigned integers.

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.

func (Field) Equals added in v0.1.3

func (f Field) Equals(other Field) bool

Equals returns whether two fields are equal. For non-primitive types such as errors, marshalers, or reflect types, it uses reflect.DeepEqual.

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) Debug

func (l *StdLogger) Debug(args ...interface{})

func (*StdLogger) Debugf

func (l *StdLogger) Debugf(format string, args ...interface{})

func (*StdLogger) Debugw added in v0.1.3

func (l *StdLogger) Debugw(msg string, kvs ...interface{})

func (*StdLogger) Enable

func (l *StdLogger) Enable(level types.Level) bool

func (*StdLogger) Error

func (l *StdLogger) Error(args ...interface{})

func (*StdLogger) Errorf

func (l *StdLogger) Errorf(format string, args ...interface{})

func (*StdLogger) Errorw added in v0.1.3

func (l *StdLogger) Errorw(msg string, kvs ...interface{})

func (*StdLogger) Fatal

func (l *StdLogger) Fatal(args ...interface{})

func (*StdLogger) Fatalf

func (l *StdLogger) Fatalf(format string, args ...interface{})

func (*StdLogger) Fatalw added in v0.1.3

func (l *StdLogger) Fatalw(msg string, kvs ...interface{})

func (*StdLogger) GetLevel

func (l *StdLogger) GetLevel() types.Level

func (*StdLogger) GetRaw

func (l *StdLogger) GetRaw() interface{}

func (*StdLogger) Info

func (l *StdLogger) Info(args ...interface{})

func (*StdLogger) Infof

func (l *StdLogger) Infof(format string, args ...interface{})

func (*StdLogger) Infow added in v0.1.3

func (l *StdLogger) Infow(msg string, kvs ...interface{})

func (*StdLogger) OpenMsgFormat added in v0.1.3

func (l *StdLogger) OpenMsgFormat()

func (*StdLogger) SetLevel

func (l *StdLogger) SetLevel(level types.Level)

func (*StdLogger) Warn

func (l *StdLogger) Warn(args ...interface{})

func (*StdLogger) Warnf

func (l *StdLogger) Warnf(format string, args ...interface{})

func (*StdLogger) Warnw added in v0.1.3

func (l *StdLogger) Warnw(msg string, kvs ...interface{})

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

Directories

Path Synopsis
Package buffer provides a thin wrapper around a byte slice.
Package buffer provides a thin wrapper around a byte slice.

Jump to

Keyboard shortcuts

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