encoder

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 6 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

This section is empty.

Functions

func AddFields

func AddFields(enc zapcore.ObjectEncoder, fields []zapcore.Field)

func EpochMillisTimeEncoder

func EpochMillisTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

EpochMillisTimeEncoder serializes a time.Time to a floating-point number of milliseconds since the Unix epoch.

func EpochNanosTimeEncoder

func EpochNanosTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

EpochNanosTimeEncoder serializes a time.Time to an integer number of nanoseconds since the Unix epoch.

func EpochTimeEncoder

func EpochTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

EpochTimeEncoder serializes a time.Time to a floating-point number of seconds since the Unix epoch.

func FullNameEncoder

func FullNameEncoder(loggerName string, enc zapcore.PrimitiveArrayEncoder)

FullNameEncoder serializes the logger name as-is.

func ISO8601TimeEncoder

func ISO8601TimeEncoder(t time.Time, enc zapcore.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

func MillisDurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)

MillisDurationEncoder serializes a time.Duration to an integer number of milliseconds elapsed.

func NanosDurationEncoder

func NanosDurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)

NanosDurationEncoder serializes a time.Duration to an integer number of nanoseconds elapsed.

func RFC3339NanoTimeEncoder

func RFC3339NanoTimeEncoder(t time.Time, enc zapcore.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

func RFC3339TimeEncoder(t time.Time, enc zapcore.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 SecondsDurationEncoder

func SecondsDurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)

SecondsDurationEncoder serializes a time.Duration to a floating-point number of seconds elapsed.

func StringDurationEncoder

func StringDurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)

StringDurationEncoder serializes a time.Duration using its built-in String method.

Types

type ArrayMarshalerFunc

type ArrayMarshalerFunc func(zapcore.ArrayEncoder) error

ArrayMarshalerFunc is a type adapter that turns a function into an ArrayMarshaler.

func (ArrayMarshalerFunc) MarshalLogArray

func (f ArrayMarshalerFunc) MarshalLogArray(enc zapcore.ArrayEncoder) error

MarshalLogArray calls the underlying function.

type DurationEncoder

type DurationEncoder func(time.Duration, zapcore.PrimitiveArrayEncoder)

A DurationEncoder serializes a time.Duration to a primitive type.

func (*DurationEncoder) UnmarshalText

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 EncoderConfig

type EncoderConfig struct {
	// Set the keys used for each log entry. If any key is empty, that portion
	// of the entry is omitted.
	MessageKey    string `json:"messageKey" yaml:"messageKey"`
	LevelKey      string `json:"levelKey" yaml:"levelKey"`
	TimeKey       string `json:"timeKey" yaml:"timeKey"`
	NameKey       string `json:"nameKey" yaml:"nameKey"`
	CallerKey     string `json:"callerKey" yaml:"callerKey"`
	FunctionKey   string `json:"functionKey" yaml:"functionKey"`
	StacktraceKey string `json:"stacktraceKey" yaml:"stacktraceKey"`
	LineEnding    string `json:"lineEnding" yaml:"lineEnding"`
	// Configure the primitive representations of common complex types. For
	// example, some users may want all time.Times serialized as floating-point
	// seconds since epoch, while others may prefer ISO8601 strings.
	EncodeTime     TimeEncoder     `json:"timeEncoder" yaml:"timeEncoder"`
	EncodeDuration DurationEncoder `json:"durationEncoder" yaml:"durationEncoder"`

	// Unlike the other primitive type encoders, EncodeName is optional. The
	// zero value falls back to FullNameEncoder.
	EncodeName NameEncoder `json:"nameEncoder" yaml:"nameEncoder"`
	// Configures the field separator used by the console encoder. Defaults
	// to tab.
	ConsoleSeparator string `json:"consoleSeparator" yaml:"consoleSeparator"`
}

An EncoderConfig allows users to configure the concrete encoders supplied by zapcore.

type NameEncoder

type NameEncoder func(string, zapcore.PrimitiveArrayEncoder)

A NameEncoder serializes a period-separated logger name to a primitive type.

func (*NameEncoder) UnmarshalText

func (e *NameEncoder) UnmarshalText(text []byte) error

UnmarshalText unmarshals text to a NameEncoder. Currently, everything is unmarshaled to FullNameEncoder.

type ObjectMarshalerFunc

type ObjectMarshalerFunc func(zapcore.ObjectEncoder) error

ObjectMarshalerFunc is a type adapter that turns a function into an ObjectMarshaler.

func (ObjectMarshalerFunc) MarshalLogObject

func (f ObjectMarshalerFunc) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject calls the underlying function.

type TimeEncoder

type TimeEncoder func(time.Time, zapcore.PrimitiveArrayEncoder)

A TimeEncoder serializes a time.Time to a primitive type.

func TimeEncoderOfLayout

func TimeEncoderOfLayout(layout string) TimeEncoder

TimeEncoderOfLayout returns TimeEncoder which serializes a time.Time using given layout.

func (*TimeEncoder) UnmarshalJSON

func (e *TimeEncoder) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON to a TimeEncoder as same way UnmarshalYAML does.

func (*TimeEncoder) UnmarshalText

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

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

Jump to

Keyboard shortcuts

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