package zapcore

Import Path
	go.uber.org/zap/zapcore (on go.dev)

Dependency Relation
	imports 21 packages, and imported by 4 packages

Involved Source Files buffered_write_syncer.go clock.go console_encoder.go core.go Package zapcore defines and implements the low-level interfaces upon which zap is built. By providing alternate implementations of these interfaces, external packages can extend zap's capabilities. encoder.go entry.go error.go field.go hook.go increase_level.go json_encoder.go lazy_with.go level.go level_strings.go marshaler.go memory_encoder.go reflected_encoder.go sampler.go tee.go write_syncer.go
Package-Level Type Names (total 52, in which 31 are exported)
/* sort exporteds by: | */
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). Logging-specific marshalers. Built-in types. // for UTF-8 encoded bytes ( ArrayEncoder) AppendComplex128(complex128) ( ArrayEncoder) AppendComplex64(complex64) Time-related types. ( ArrayEncoder) AppendFloat32(float32) ( ArrayEncoder) AppendFloat64(float64) ( ArrayEncoder) AppendInt(int) ( ArrayEncoder) AppendInt16(int16) ( ArrayEncoder) AppendInt32(int32) ( ArrayEncoder) AppendInt64(int64) ( ArrayEncoder) AppendInt8(int8) ( ArrayEncoder) AppendObject(ObjectMarshaler) error AppendReflected uses reflection to serialize arbitrary objects, so it's slow and allocation-heavy. ( ArrayEncoder) AppendString(string) ( ArrayEncoder) AppendTime(time.Time) ( ArrayEncoder) AppendUint(uint) ( ArrayEncoder) AppendUint16(uint16) ( ArrayEncoder) AppendUint32(uint32) ( ArrayEncoder) AppendUint64(uint64) ( ArrayEncoder) AppendUint8(uint8) ( ArrayEncoder) AppendUintptr(uintptr) ArrayEncoder : PrimitiveArrayEncoder func ArrayMarshaler.MarshalLogArray(ArrayEncoder) error func ArrayMarshalerFunc.MarshalLogArray(enc 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. ( ArrayMarshaler) MarshalLogArray(ArrayEncoder) error ArrayMarshalerFunc func ArrayEncoder.AppendArray(ArrayMarshaler) error func Encoder.AddArray(key string, marshaler ArrayMarshaler) error func (*MapObjectEncoder).AddArray(key string, v ArrayMarshaler) error func ObjectEncoder.AddArray(key string, marshaler ArrayMarshaler) error func go.uber.org/zap.Array(key string, val ArrayMarshaler) zap.Field
ArrayMarshalerFunc is a type adapter that turns a function into an ArrayMarshaler. MarshalLogArray calls the underlying function. ArrayMarshalerFunc : ArrayMarshaler
A BufferedWriteSyncer is a WriteSyncer that buffers writes in-memory before flushing them to a wrapped WriteSyncer after reaching some limit, or at some fixed interval--whichever comes first. BufferedWriteSyncer is safe for concurrent use. You don't need to use zapcore.Lock for WriteSyncers with BufferedWriteSyncer. To set up a BufferedWriteSyncer, construct a WriteSyncer for your log destination (*os.File is a valid WriteSyncer), wrap it with BufferedWriteSyncer, and defer a Stop() call for when you no longer need the object. func main() { ws := ... // your log destination bws := &zapcore.BufferedWriteSyncer{WS: ws} defer bws.Stop() // ... core := zapcore.NewCore(enc, bws, lvl) logger := zap.New(core) // ... } By default, a BufferedWriteSyncer will buffer up to 256 kilobytes of logs, waiting at most 30 seconds between flushes. You can customize these parameters by setting the Size or FlushInterval fields. For example, the following buffers up to 512 kB of logs before flushing them to Stderr, with a maximum of one minute between each flush. ws := &BufferedWriteSyncer{ WS: os.Stderr, Size: 512 * 1024, // 512 kB FlushInterval: time.Minute, } defer ws.Stop() Clock, if specified, provides control of the source of time for the writer. Defaults to the system clock. FlushInterval specifies how often the writer should flush data if there have been no writes. Defaults to 30 seconds if unspecified. Size specifies the maximum amount of data the writer will buffered before flushing. Defaults to 256 kB if unspecified. WS is the WriteSyncer around which BufferedWriteSyncer will buffer writes. This field is required. Stop closes the buffer, cleans up background goroutines, and flushes remaining unwritten data. Sync flushes buffered log data into disk directly. Write writes log data into buffer syncer directly, multiple Write calls will be batched, and log data will be flushed to disk when the buffer is full or periodically. *BufferedWriteSyncer : WriteSyncer *BufferedWriteSyncer : internal/bisect.Writer *BufferedWriteSyncer : io.Writer
A CallerEncoder serializes an EntryCaller to a primitive type. UnmarshalText unmarshals text to a CallerEncoder. "full" is unmarshaled to FullCallerEncoder and anything else is unmarshaled to ShortCallerEncoder. *CallerEncoder : encoding.TextUnmarshaler
CheckedEntry is an Entry together with a collection of Cores that have already agreed to log it. CheckedEntry references should be created by calling AddCore or After on a nil *CheckedEntry. References are returned to a pool after Write, and MUST NOT be retained after calling their Write method. Entry Entry Entry.Caller EntryCaller Entry.Level Level Entry.LoggerName string Entry.Message string Entry.Stack string Entry.Time time.Time ErrorOutput WriteSyncer AddCore adds a Core that has agreed to log this CheckedEntry. It's intended to be used by Core.Check implementations, and is safe to call on nil CheckedEntry references. After sets this CheckEntry's CheckWriteHook, which will be called after this log entry has been written. It's safe to call this on nil CheckedEntry references. Should sets this CheckedEntry's CheckWriteAction, which controls whether a Core will panic or fatal after writing this log entry. Like AddCore, it's safe to call on nil CheckedEntry references. Deprecated: Use [CheckedEntry.After] instead. Write writes the entry to the stored Cores, returns any errors, and returns the CheckedEntry reference to a pool for immediate re-use. Finally, it executes any required CheckWriteAction. func (*CheckedEntry).AddCore(ent Entry, core Core) *CheckedEntry func (*CheckedEntry).After(ent Entry, hook CheckWriteHook) *CheckedEntry func (*CheckedEntry).Should(ent Entry, should CheckWriteAction) *CheckedEntry func Core.Check(Entry, *CheckedEntry) *CheckedEntry func go.uber.org/zap.(*Logger).Check(lvl Level, msg string) *CheckedEntry func CheckWriteAction.OnWrite(ce *CheckedEntry, _ []Field) func CheckWriteHook.OnWrite(*CheckedEntry, []Field) func Core.Check(Entry, *CheckedEntry) *CheckedEntry
CheckWriteAction indicates what action to take after a log entry is processed. Actions are ordered in increasing severity. OnWrite implements the OnWrite method to keep CheckWriteAction compatible with the new CheckWriteHook interface which deprecates CheckWriteAction. CheckWriteAction : CheckWriteHook func (*CheckedEntry).Should(ent Entry, should CheckWriteAction) *CheckedEntry func go.uber.org/zap.OnFatal(action CheckWriteAction) zap.Option const WriteThenFatal const WriteThenGoexit const WriteThenNoop const WriteThenPanic
CheckWriteHook is a custom action that may be executed after an entry is written. Register one on a CheckedEntry with the After method. if ce := logger.Check(...); ce != nil { ce = ce.After(hook) ce.Write(...) } You can configure the hook for Fatal log statements at the logger level with the zap.WithFatalHook option. OnWrite is invoked with the CheckedEntry that was written and a list of fields added with that entry. The list of fields DOES NOT include fields that were already added to the logger with the With method. CheckWriteAction func (*CheckedEntry).After(ent Entry, hook CheckWriteHook) *CheckedEntry func go.uber.org/zap.WithFatalHook(hook CheckWriteHook) zap.Option
Clock is a source of time for logged entries. NewTicker returns *time.Ticker that holds a channel that delivers "ticks" of a clock. Now returns the current local time. Clock : github.com/cenkalti/backoff/v4.Clock func go.uber.org/zap.WithClock(clock Clock) zap.Option
Core is a minimal, fast logger interface. It's designed for library authors to wrap in a more user-friendly API. Check determines whether the supplied Entry should be logged (using the embedded LevelEnabler and possibly some extra logic). If the entry should be logged, the Core adds itself to the CheckedEntry and returns the result. Callers must use Check before calling Write. ( Core) Enabled(Level) bool Sync flushes buffered logs (if any). With adds structured context to the Core. Write serializes the Entry and any Fields supplied at the log site and writes them to their destination. If called, Write should always log the Entry and Fields; it should not replicate the logic of Check. Core : LevelEnabler func NewCore(enc Encoder, ws WriteSyncer, enab LevelEnabler) Core func NewIncreaseLevelCore(core Core, level LevelEnabler) (Core, error) func NewLazyWith(core Core, fields []Field) Core func NewNopCore() Core func NewSampler(core Core, tick time.Duration, first, thereafter int) Core func NewSamplerWithOptions(core Core, tick time.Duration, first, thereafter int, opts ...SamplerOption) Core func NewTee(cores ...Core) Core func RegisterHooks(core Core, hooks ...func(Entry) error) Core func Core.With([]Field) Core func go.uber.org/zap.(*Logger).Core() Core func NewIncreaseLevelCore(core Core, level LevelEnabler) (Core, error) func NewLazyWith(core Core, fields []Field) Core func NewSampler(core Core, tick time.Duration, first, thereafter int) Core func NewSamplerWithOptions(core Core, tick time.Duration, first, thereafter int, opts ...SamplerOption) Core func NewTee(cores ...Core) Core func RegisterHooks(core Core, hooks ...func(Entry) error) Core func (*CheckedEntry).AddCore(ent Entry, core Core) *CheckedEntry func go.uber.org/zap.New(core Core, options ...zap.Option) *zap.Logger
A DurationEncoder serializes a time.Duration to a primitive type. UnmarshalText unmarshals text to a DurationEncoder. "string" is unmarshaled to StringDurationEncoder, and anything else is unmarshaled to NanosDurationEncoder. *DurationEncoder : encoding.TextUnmarshaler
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. Logging-specific marshalers. Built-in types. // for arbitrary bytes ( Encoder) AddBool(key string, value bool) // for UTF-8 encoded bytes ( Encoder) AddComplex128(key string, value complex128) ( Encoder) AddComplex64(key string, value complex64) ( Encoder) AddDuration(key string, value time.Duration) ( Encoder) AddFloat32(key string, value float32) ( Encoder) AddFloat64(key string, value float64) ( Encoder) AddInt(key string, value int) ( Encoder) AddInt16(key string, value int16) ( Encoder) AddInt32(key string, value int32) ( Encoder) AddInt64(key string, value int64) ( Encoder) AddInt8(key string, value int8) ( Encoder) AddObject(key string, marshaler ObjectMarshaler) error AddReflected uses reflection to serialize arbitrary objects, so it can be slow and allocation-heavy. ( Encoder) AddString(key, value string) ( Encoder) AddTime(key string, value time.Time) ( Encoder) AddUint(key string, value uint) ( Encoder) AddUint16(key string, value uint16) ( Encoder) AddUint32(key string, value uint32) ( Encoder) AddUint64(key string, value uint64) ( Encoder) AddUint8(key string, value uint8) ( Encoder) AddUintptr(key string, value uintptr) Clone copies the encoder, ensuring that adding fields to the copy doesn't affect the original. 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. 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. Encoder : ObjectEncoder func NewConsoleEncoder(cfg EncoderConfig) Encoder func NewJSONEncoder(cfg EncoderConfig) Encoder func Encoder.Clone() Encoder func NewCore(enc Encoder, ws WriteSyncer, enab LevelEnabler) Core
An EncoderConfig allows users to configure the concrete encoders supplied by zapcore. CallerKey string Configures the field separator used by the console encoder. Defaults to tab. EncodeCaller CallerEncoder EncodeDuration DurationEncoder 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. Unlike the other primitive type encoders, EncodeName is optional. The zero value falls back to FullNameEncoder. EncodeTime TimeEncoder FunctionKey string LevelKey string LineEnding string Set the keys used for each log entry. If any key is empty, that portion of the entry is omitted. NameKey string Configure the encoder for interface{} type objects. If not provided, objects are encoded using json.Encoder SkipLineEnding bool StacktraceKey string TimeKey string func go.uber.org/zap.NewDevelopmentEncoderConfig() EncoderConfig func go.uber.org/zap.NewProductionEncoderConfig() EncoderConfig func NewConsoleEncoder(cfg EncoderConfig) Encoder func NewJSONEncoder(cfg EncoderConfig) Encoder
An Entry represents a complete log message. The entry's structured context is already serialized, but the log level, time, message, and call site information are available for inspection and modification. Any fields left empty will be omitted when encoding. Entries are pooled, so any functions that accept them MUST be careful not to retain references to them. Caller EntryCaller Level Level LoggerName string Message string Stack string Time time.Time func (*CheckedEntry).AddCore(ent Entry, core Core) *CheckedEntry func (*CheckedEntry).After(ent Entry, hook CheckWriteHook) *CheckedEntry func (*CheckedEntry).Should(ent Entry, should CheckWriteAction) *CheckedEntry func Core.Check(Entry, *CheckedEntry) *CheckedEntry func Core.Write(Entry, []Field) error func Encoder.EncodeEntry(Entry, []Field) (*buffer.Buffer, error)
EntryCaller represents the caller of a logging function. Defined bool File string Function string Line int PC uintptr FullPath returns a /full/path/to/package/file:line description of the caller. String returns the full path and line number of the caller. TrimmedPath returns a package/file:line description of the caller, preserving only the leaf directory name and file name. EntryCaller : fmt.Stringer func NewEntryCaller(pc uintptr, file string, line int, ok bool) EntryCaller func FullCallerEncoder(caller EntryCaller, enc PrimitiveArrayEncoder) func ShortCallerEncoder(caller EntryCaller, enc PrimitiveArrayEncoder)
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. Integer int64 Interface interface{} Key string String string Type FieldType AddTo exports a field through the ObjectEncoder interface. It's primarily useful to library authors, and shouldn't be necessary in most applications. Equals returns whether two fields are equal. For non-primitive types such as errors, marshalers, or reflect types, it uses reflect.DeepEqual. func go.uber.org/zap.Any(key string, value interface{}) zap.Field func go.uber.org/zap.Array(key string, val ArrayMarshaler) zap.Field func go.uber.org/zap.Binary(key string, val []byte) zap.Field func go.uber.org/zap.Bool(key string, val bool) zap.Field func go.uber.org/zap.Boolp(key string, val *bool) zap.Field func go.uber.org/zap.Bools(key string, bs []bool) zap.Field func go.uber.org/zap.ByteString(key string, val []byte) zap.Field func go.uber.org/zap.ByteStrings(key string, bss [][]byte) zap.Field func go.uber.org/zap.Complex128(key string, val complex128) zap.Field func go.uber.org/zap.Complex128p(key string, val *complex128) zap.Field func go.uber.org/zap.Complex128s(key string, nums []complex128) zap.Field func go.uber.org/zap.Complex64(key string, val complex64) zap.Field func go.uber.org/zap.Complex64p(key string, val *complex64) zap.Field func go.uber.org/zap.Complex64s(key string, nums []complex64) zap.Field func go.uber.org/zap.Dict(key string, val ...zap.Field) zap.Field func go.uber.org/zap.Duration(key string, val time.Duration) zap.Field func go.uber.org/zap.Durationp(key string, val *time.Duration) zap.Field func go.uber.org/zap.Durations(key string, ds []time.Duration) zap.Field func go.uber.org/zap.Error(err error) zap.Field func go.uber.org/zap.Errors(key string, errs []error) zap.Field func go.uber.org/zap.Float32(key string, val float32) zap.Field func go.uber.org/zap.Float32p(key string, val *float32) zap.Field func go.uber.org/zap.Float32s(key string, nums []float32) zap.Field func go.uber.org/zap.Float64(key string, val float64) zap.Field func go.uber.org/zap.Float64p(key string, val *float64) zap.Field func go.uber.org/zap.Float64s(key string, nums []float64) zap.Field func go.uber.org/zap.Inline(val ObjectMarshaler) zap.Field func go.uber.org/zap.Int(key string, val int) zap.Field func go.uber.org/zap.Int16(key string, val int16) zap.Field func go.uber.org/zap.Int16p(key string, val *int16) zap.Field func go.uber.org/zap.Int16s(key string, nums []int16) zap.Field func go.uber.org/zap.Int32(key string, val int32) zap.Field func go.uber.org/zap.Int32p(key string, val *int32) zap.Field func go.uber.org/zap.Int32s(key string, nums []int32) zap.Field func go.uber.org/zap.Int64(key string, val int64) zap.Field func go.uber.org/zap.Int64p(key string, val *int64) zap.Field func go.uber.org/zap.Int64s(key string, nums []int64) zap.Field func go.uber.org/zap.Int8(key string, val int8) zap.Field func go.uber.org/zap.Int8p(key string, val *int8) zap.Field func go.uber.org/zap.Int8s(key string, nums []int8) zap.Field func go.uber.org/zap.Intp(key string, val *int) zap.Field func go.uber.org/zap.Ints(key string, nums []int) zap.Field func go.uber.org/zap.NamedError(key string, err error) zap.Field func go.uber.org/zap.Namespace(key string) zap.Field func go.uber.org/zap.Object(key string, val ObjectMarshaler) zap.Field func go.uber.org/zap.Objects[T](key string, values []T) zap.Field func go.uber.org/zap.ObjectValues[T, P](key string, values []T) zap.Field func go.uber.org/zap.Reflect(key string, val interface{}) zap.Field func go.uber.org/zap.Skip() zap.Field func go.uber.org/zap.Stack(key string) zap.Field func go.uber.org/zap.StackSkip(key string, skip int) zap.Field func go.uber.org/zap.String(key string, val string) zap.Field func go.uber.org/zap.Stringer(key string, val fmt.Stringer) zap.Field func go.uber.org/zap.Stringers[T](key string, values []T) zap.Field func go.uber.org/zap.Stringp(key string, val *string) zap.Field func go.uber.org/zap.Strings(key string, ss []string) zap.Field func go.uber.org/zap.Time(key string, val time.Time) zap.Field func go.uber.org/zap.Timep(key string, val *time.Time) zap.Field func go.uber.org/zap.Times(key string, ts []time.Time) zap.Field func go.uber.org/zap.Uint(key string, val uint) zap.Field func go.uber.org/zap.Uint16(key string, val uint16) zap.Field func go.uber.org/zap.Uint16p(key string, val *uint16) zap.Field func go.uber.org/zap.Uint16s(key string, nums []uint16) zap.Field func go.uber.org/zap.Uint32(key string, val uint32) zap.Field func go.uber.org/zap.Uint32p(key string, val *uint32) zap.Field func go.uber.org/zap.Uint32s(key string, nums []uint32) zap.Field func go.uber.org/zap.Uint64(key string, val uint64) zap.Field func go.uber.org/zap.Uint64p(key string, val *uint64) zap.Field func go.uber.org/zap.Uint64s(key string, nums []uint64) zap.Field func go.uber.org/zap.Uint8(key string, val uint8) zap.Field func go.uber.org/zap.Uint8p(key string, val *uint8) zap.Field func go.uber.org/zap.Uint8s(key string, nums []uint8) zap.Field func go.uber.org/zap.Uintp(key string, val *uint) zap.Field func go.uber.org/zap.Uintptr(key string, val uintptr) zap.Field func go.uber.org/zap.Uintptrp(key string, val *uintptr) zap.Field func go.uber.org/zap.Uintptrs(key string, us []uintptr) zap.Field func go.uber.org/zap.Uints(key string, nums []uint) zap.Field func NewLazyWith(core Core, fields []Field) Core func (*CheckedEntry).Write(fields ...Field) func CheckWriteAction.OnWrite(ce *CheckedEntry, _ []Field) func CheckWriteHook.OnWrite(*CheckedEntry, []Field) func Core.With([]Field) Core func Core.Write(Entry, []Field) error func Encoder.EncodeEntry(Entry, []Field) (*buffer.Buffer, error) func Field.Equals(other Field) bool func go.uber.org/zap.Dict(key string, val ...zap.Field) zap.Field func go.uber.org/zap.Fields(fs ...zap.Field) zap.Option func go.uber.org/zap.(*Logger).Debug(msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).DPanic(msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).Error(msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).Fatal(msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).Info(msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).Log(lvl Level, msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).Panic(msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).Warn(msg string, fields ...zap.Field) func go.uber.org/zap.(*Logger).With(fields ...zap.Field) *zap.Logger func go.uber.org/zap.(*Logger).WithLazy(fields ...zap.Field) *zap.Logger
A FieldType indicates which member of the Field union struct should be used and how it should be serialized. const ArrayMarshalerType const BinaryType const BoolType const ByteStringType const Complex128Type const Complex64Type const DurationType const ErrorType const Float32Type const Float64Type const InlineMarshalerType const Int16Type const Int32Type const Int64Type const Int8Type const NamespaceType const ObjectMarshalerType const ReflectType const SkipType const StringerType const StringType const TimeFullType const TimeType const Uint16Type const Uint32Type const Uint64Type const Uint8Type const UintptrType const UnknownType
A Level is a logging priority. Higher levels are more important. CapitalString returns an all-caps ASCII representation of the log level. Enabled returns true if the given level is at or above this level. Get gets the level for the flag.Getter interface. MarshalText marshals the Level to text. Note that the text representation drops the -Level suffix (see example). Set sets the level for the flag.Value interface. String returns a lower-case ASCII representation of the log level. UnmarshalText unmarshals text to a level. Like MarshalText, UnmarshalText expects the text representation of a Level to drop the -Level suffix (see example). In particular, this makes it easy to configure logging levels using YAML, TOML, or JSON files. Level : LevelEnabler Level : encoding.TextMarshaler *Level : encoding.TextUnmarshaler *Level : flag.Getter *Level : flag.Value Level : fmt.Stringer func LevelOf(enab LevelEnabler) Level func ParseLevel(text string) (Level, error) func go.uber.org/zap.LevelFlag(name string, defaultLevel Level, usage string) *Level func go.uber.org/zap.AtomicLevel.Level() Level func go.uber.org/zap.(*Logger).Level() Level func go.uber.org/zap.(*SugaredLogger).Level() Level func go.uber.org/zap/internal.LeveledEnabler.Level() Level func CapitalColorLevelEncoder(l Level, enc PrimitiveArrayEncoder) func CapitalLevelEncoder(l Level, enc PrimitiveArrayEncoder) func LowercaseColorLevelEncoder(l Level, enc PrimitiveArrayEncoder) func LowercaseLevelEncoder(l Level, enc PrimitiveArrayEncoder) func Core.Enabled(Level) bool func Level.Enabled(lvl Level) bool func LevelEnabler.Enabled(Level) bool func go.uber.org/zap.LevelFlag(name string, defaultLevel Level, usage string) *Level func go.uber.org/zap.NewAtomicLevelAt(l Level) zap.AtomicLevel func go.uber.org/zap.NewStdLogAt(l *zap.Logger, level Level) (*log.Logger, error) func go.uber.org/zap.RedirectStdLogAt(l *zap.Logger, level Level) (func(), error) func go.uber.org/zap.AtomicLevel.Enabled(l Level) bool func go.uber.org/zap.AtomicLevel.SetLevel(l Level) func go.uber.org/zap.LevelEnablerFunc.Enabled(lvl Level) bool func go.uber.org/zap.(*Logger).Check(lvl Level, msg string) *CheckedEntry func go.uber.org/zap.(*Logger).Log(lvl Level, msg string, fields ...zap.Field) func go.uber.org/zap/internal.LeveledEnabler.Enabled(Level) bool const DebugLevel const DPanicLevel const ErrorLevel const FatalLevel const InfoLevel const InvalidLevel const PanicLevel const WarnLevel const go.uber.org/zap.DebugLevel const go.uber.org/zap.DPanicLevel const go.uber.org/zap.ErrorLevel const go.uber.org/zap.FatalLevel const go.uber.org/zap.InfoLevel const go.uber.org/zap.PanicLevel const go.uber.org/zap.WarnLevel
LevelEnabler decides whether a given logging level is enabled when logging a message. Enablers are intended to be used to implement deterministic filters; concerns like sampling are better implemented as a Core. Each concrete Level value implements a static LevelEnabler which returns true for itself and all higher logging levels. For example WarnLevel.Enabled() will return true for WarnLevel, ErrorLevel, DPanicLevel, PanicLevel, and FatalLevel, but return false for InfoLevel and DebugLevel. ( LevelEnabler) Enabled(Level) bool Core (interface) Level go.uber.org/zap.AtomicLevel go.uber.org/zap.LevelEnablerFunc go.uber.org/zap/internal.LeveledEnabler (interface) func LevelOf(enab LevelEnabler) Level func NewCore(enc Encoder, ws WriteSyncer, enab LevelEnabler) Core func NewIncreaseLevelCore(core Core, level LevelEnabler) (Core, error) func go.uber.org/zap.AddStacktrace(lvl LevelEnabler) zap.Option func go.uber.org/zap.IncreaseLevel(lvl LevelEnabler) zap.Option
A LevelEncoder serializes a Level to a primitive type. UnmarshalText unmarshals text to a LevelEncoder. "capital" is unmarshaled to CapitalLevelEncoder, "coloredCapital" is unmarshaled to CapitalColorLevelEncoder, "colored" is unmarshaled to LowercaseColorLevelEncoder, and anything else is unmarshaled to LowercaseLevelEncoder. *LevelEncoder : encoding.TextUnmarshaler
MapObjectEncoder is an ObjectEncoder backed by a simple map[string]interface{}. It's not fast enough for production use, but it's helpful in tests. Fields contains the entire encoded log context. AddArray implements ObjectEncoder. AddBinary implements ObjectEncoder. AddBool implements ObjectEncoder. AddByteString implements ObjectEncoder. AddComplex128 implements ObjectEncoder. AddComplex64 implements ObjectEncoder. AddDuration implements ObjectEncoder. AddFloat32 implements ObjectEncoder. AddFloat64 implements ObjectEncoder. AddInt implements ObjectEncoder. AddInt16 implements ObjectEncoder. AddInt32 implements ObjectEncoder. AddInt64 implements ObjectEncoder. AddInt8 implements ObjectEncoder. AddObject implements ObjectEncoder. AddReflected implements ObjectEncoder. AddString implements ObjectEncoder. AddTime implements ObjectEncoder. AddUint implements ObjectEncoder. AddUint16 implements ObjectEncoder. AddUint32 implements ObjectEncoder. AddUint64 implements ObjectEncoder. AddUint8 implements ObjectEncoder. AddUintptr implements ObjectEncoder. OpenNamespace implements ObjectEncoder. *MapObjectEncoder : ObjectEncoder func NewMapObjectEncoder() *MapObjectEncoder
A NameEncoder serializes a period-separated logger name to a primitive type. UnmarshalText unmarshals text to a NameEncoder. Currently, everything is unmarshaled to FullNameEncoder. *NameEncoder : encoding.TextUnmarshaler
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). Logging-specific marshalers. Built-in types. // for arbitrary bytes ( ObjectEncoder) AddBool(key string, value bool) // for UTF-8 encoded bytes ( ObjectEncoder) AddComplex128(key string, value complex128) ( ObjectEncoder) AddComplex64(key string, value complex64) ( ObjectEncoder) AddDuration(key string, value time.Duration) ( ObjectEncoder) AddFloat32(key string, value float32) ( ObjectEncoder) AddFloat64(key string, value float64) ( ObjectEncoder) AddInt(key string, value int) ( ObjectEncoder) AddInt16(key string, value int16) ( ObjectEncoder) AddInt32(key string, value int32) ( ObjectEncoder) AddInt64(key string, value int64) ( ObjectEncoder) AddInt8(key string, value int8) ( ObjectEncoder) AddObject(key string, marshaler ObjectMarshaler) error AddReflected uses reflection to serialize arbitrary objects, so it can be slow and allocation-heavy. ( ObjectEncoder) AddString(key, value string) ( ObjectEncoder) AddTime(key string, value time.Time) ( ObjectEncoder) AddUint(key string, value uint) ( ObjectEncoder) AddUint16(key string, value uint16) ( ObjectEncoder) AddUint32(key string, value uint32) ( ObjectEncoder) AddUint64(key string, value uint64) ( ObjectEncoder) AddUint8(key string, value uint8) ( ObjectEncoder) AddUintptr(key string, value uintptr) 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. Encoder (interface) *MapObjectEncoder func Field.AddTo(enc ObjectEncoder) func ObjectMarshaler.MarshalLogObject(ObjectEncoder) error func ObjectMarshalerFunc.MarshalLogObject(enc ObjectEncoder) error func go.uber.org/zap.ObjectMarshalerPtr.MarshalLogObject(ObjectEncoder) error func github.com/gotd/td/internal/crypto.AuthKey.MarshalLogObject(encoder 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. ( ObjectMarshaler) MarshalLogObject(ObjectEncoder) error ObjectMarshalerFunc go.uber.org/zap.ObjectMarshalerPtr[...] (interface) github.com/gotd/td/internal/crypto.AuthKey ObjectMarshaler : go.uber.org/zap.ObjectMarshalerPtr[...] func ArrayEncoder.AppendObject(ObjectMarshaler) error func Encoder.AddObject(key string, marshaler ObjectMarshaler) error func (*MapObjectEncoder).AddObject(k string, v ObjectMarshaler) error func ObjectEncoder.AddObject(key string, marshaler ObjectMarshaler) error func go.uber.org/zap.Inline(val ObjectMarshaler) zap.Field func go.uber.org/zap.Object(key string, val ObjectMarshaler) zap.Field
ObjectMarshalerFunc is a type adapter that turns a function into an ObjectMarshaler. MarshalLogObject calls the underlying function. ObjectMarshalerFunc : ObjectMarshaler[T] ObjectMarshalerFunc : go.uber.org/zap.ObjectMarshalerPtr[...]
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. Built-in types. // for UTF-8 encoded bytes ( PrimitiveArrayEncoder) AppendComplex128(complex128) ( PrimitiveArrayEncoder) AppendComplex64(complex64) ( PrimitiveArrayEncoder) AppendFloat32(float32) ( PrimitiveArrayEncoder) AppendFloat64(float64) ( PrimitiveArrayEncoder) AppendInt(int) ( PrimitiveArrayEncoder) AppendInt16(int16) ( PrimitiveArrayEncoder) AppendInt32(int32) ( PrimitiveArrayEncoder) AppendInt64(int64) ( PrimitiveArrayEncoder) AppendInt8(int8) ( PrimitiveArrayEncoder) AppendString(string) ( PrimitiveArrayEncoder) AppendUint(uint) ( PrimitiveArrayEncoder) AppendUint16(uint16) ( PrimitiveArrayEncoder) AppendUint32(uint32) ( PrimitiveArrayEncoder) AppendUint64(uint64) ( PrimitiveArrayEncoder) AppendUint8(uint8) ( PrimitiveArrayEncoder) AppendUintptr(uintptr) ArrayEncoder (interface) func CapitalColorLevelEncoder(l Level, enc PrimitiveArrayEncoder) func CapitalLevelEncoder(l Level, enc PrimitiveArrayEncoder) func EpochMillisTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) func EpochNanosTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) func EpochTimeEncoder(t time.Time, enc PrimitiveArrayEncoder) func FullCallerEncoder(caller EntryCaller, enc PrimitiveArrayEncoder) func FullNameEncoder(loggerName string, enc PrimitiveArrayEncoder) func ISO8601TimeEncoder(t time.Time, enc PrimitiveArrayEncoder) func LowercaseColorLevelEncoder(l Level, enc PrimitiveArrayEncoder) func LowercaseLevelEncoder(l Level, enc PrimitiveArrayEncoder) 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 SecondsDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder) func ShortCallerEncoder(caller EntryCaller, enc PrimitiveArrayEncoder) func StringDurationEncoder(d time.Duration, enc PrimitiveArrayEncoder)
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. Encode encodes and writes to the underlying data stream. *encoding/json.Encoder
SamplerOption configures a Sampler. func SamplerHook(hook func(entry Entry, dec SamplingDecision)) SamplerOption func NewSamplerWithOptions(core Core, tick time.Duration, first, thereafter int, opts ...SamplerOption) Core
SamplingDecision is a decision represented as a bit field made by sampler. More decisions may be added in the future. const LogDropped const LogSampled
A TimeEncoder serializes a time.Time to a primitive type. UnmarshalJSON unmarshals JSON to a TimeEncoder as same way UnmarshalYAML does. 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. 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 *TimeEncoder : encoding.TextUnmarshaler *TimeEncoder : encoding/json.Unmarshaler func TimeEncoderOfLayout(layout string) TimeEncoder
A WriteSyncer is an io.Writer that can also flush any buffered data. Note that *os.File (and thus, os.Stderr and os.Stdout) implement WriteSyncer. ( WriteSyncer) Sync() error ( WriteSyncer) Write([]byte) (int, error) *BufferedWriteSyncer go.uber.org/zap.Sink (interface) *os.File WriteSyncer : internal/bisect.Writer WriteSyncer : io.Writer func AddSync(w io.Writer) WriteSyncer func Lock(ws WriteSyncer) WriteSyncer func NewMultiWriteSyncer(ws ...WriteSyncer) WriteSyncer func go.uber.org/zap.CombineWriteSyncers(writers ...WriteSyncer) WriteSyncer func go.uber.org/zap.Open(paths ...string) (WriteSyncer, func(), error) func Lock(ws WriteSyncer) WriteSyncer func NewCore(enc Encoder, ws WriteSyncer, enab LevelEnabler) Core func NewMultiWriteSyncer(ws ...WriteSyncer) WriteSyncer func go.uber.org/zap.CombineWriteSyncers(writers ...WriteSyncer) WriteSyncer func go.uber.org/zap.ErrorOutput(w WriteSyncer) zap.Option
Package-Level Functions (total 53, in which 36 are exported)
AddSync converts an io.Writer to a WriteSyncer. It attempts to be intelligent: if the concrete type of the io.Writer implements WriteSyncer, we'll use the existing Sync method. If it doesn't, we'll add a no-op Sync.
CapitalColorLevelEncoder serializes a Level to an all-caps string and adds color. For example, InfoLevel is serialized to "INFO" and colored blue.
CapitalLevelEncoder serializes a Level to an all-caps string. For example, InfoLevel is serialized to "INFO".
EpochMillisTimeEncoder serializes a time.Time to a floating-point number of milliseconds since the Unix epoch.
EpochNanosTimeEncoder serializes a time.Time to an integer number of nanoseconds since the Unix epoch.
EpochTimeEncoder serializes a time.Time to a floating-point number of seconds since the Unix epoch.
FullCallerEncoder serializes a caller in /full/path/to/package/file:line format.
FullNameEncoder serializes the logger name as-is.
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.
LevelOf reports the minimum enabled log level for the given LevelEnabler from Zap's supported log levels, or [InvalidLevel] if none of them are enabled. A LevelEnabler may implement a 'Level() Level' method to override the behavior of this function. func (c *core) Level() Level { return c.currentLevel } It is recommended that [Core] implementations that wrap other cores use LevelOf to retrieve the level of the wrapped core. For example, func (c *coreWrapper) Level() Level { return zapcore.LevelOf(c.wrappedCore) }
Lock wraps a WriteSyncer in a mutex to make it safe for concurrent use. In particular, *os.Files must be locked before use.
LowercaseColorLevelEncoder serializes a Level to a lowercase string and adds coloring. For example, InfoLevel is serialized to "info" and colored blue.
LowercaseLevelEncoder serializes a Level to a lowercase string. For example, InfoLevel is serialized to "info".
MillisDurationEncoder serializes a time.Duration to an integer number of milliseconds elapsed.
NanosDurationEncoder serializes a time.Duration to an integer number of nanoseconds elapsed.
NewConsoleEncoder creates an encoder whose output is designed for human - rather than machine - consumption. It serializes the core log entry data (message, level, timestamp, etc.) in a plain-text format and leaves the structured context as JSON. Note that although the console encoder doesn't use the keys specified in the encoder configuration, it will omit any element whose key is set to the empty string.
NewCore creates a Core that writes logs to a WriteSyncer.
NewEntryCaller makes an EntryCaller from the return signature of runtime.Caller.
NewIncreaseLevelCore creates a core that can be used to increase the level of an existing Core. It cannot be used to decrease the logging level, as it acts as a filter before calling the underlying core. If level decreases the log level, an error is returned.
NewJSONEncoder creates a fast, low-allocation JSON encoder. The encoder appropriately escapes all field keys and values. Note that the encoder doesn't deduplicate keys, so it's possible to produce a message like {"foo":"bar","foo":"baz"} This is permitted by the JSON specification, but not encouraged. Many libraries will ignore duplicate key-value pairs (typically keeping the last pair) when unmarshaling, but users should attempt to avoid adding duplicate keys.
NewLazyWith wraps a Core with a "lazy" Core that will only encode fields if the logger is written to (or is further chained in a lon-lazy manner).
NewMapObjectEncoder creates a new map-backed ObjectEncoder.
NewMultiWriteSyncer creates a WriteSyncer that duplicates its writes and sync calls, much like io.MultiWriter.
NewNopCore returns a no-op Core.
NewSampler creates a Core that samples incoming entries, which caps the CPU and I/O load of logging while attempting to preserve a representative subset of your logs. Zap samples by logging the first N entries with a given level and message each tick. If more Entries with the same level and message are seen during the same interval, every Mth message is logged and the rest are dropped. Keep in mind that zap's sampling implementation is optimized for speed over absolute precision; under load, each tick may be slightly over- or under-sampled. Deprecated: use NewSamplerWithOptions.
NewSamplerWithOptions creates a Core that samples incoming entries, which caps the CPU and I/O load of logging while attempting to preserve a representative subset of your logs. Zap samples by logging the first N entries with a given level and message each tick. If more Entries with the same level and message are seen during the same interval, every Mth message is logged and the rest are dropped. For example, core = NewSamplerWithOptions(core, time.Second, 10, 5) This will log the first 10 log entries with the same level and message in a one second interval as-is. Following that, it will allow through every 5th log entry with the same level and message in that interval. If thereafter is zero, the Core will drop all log entries after the first N in that interval. Sampler can be configured to report sampling decisions with the SamplerHook option. Keep in mind that Zap's sampling implementation is optimized for speed over absolute precision; under load, each tick may be slightly over- or under-sampled.
NewTee creates a Core that duplicates log entries into two or more underlying Cores. Calling it with a single Core returns the input unchanged, and calling it with no input returns a no-op Core.
ParseLevel parses a level based on the lower-case or all-caps ASCII representation of the log level. If the provided ASCII representation is invalid an error is returned. This is particularly useful when dealing with text input to configure log levels.
RegisterHooks wraps a Core and runs a collection of user-defined callback hooks each time a message is logged. Execution of the callbacks is blocking. This offers users an easy way to register simple callbacks (e.g., metrics collection) without implementing the full Core interface.
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.
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.
SamplerHook registers a function which will be called when Sampler makes a decision. This hook may be used to get visibility into the performance of the sampler. For example, use it to track metrics of dropped versus sampled logs. var dropped atomic.Int64 zapcore.SamplerHook(func(ent zapcore.Entry, dec zapcore.SamplingDecision) { if dec&zapcore.LogDropped > 0 { dropped.Inc() } })
SecondsDurationEncoder serializes a time.Duration to a floating-point number of seconds elapsed.
ShortCallerEncoder serializes a caller in package/file:line format, trimming all but the final directory from the full path.
StringDurationEncoder serializes a time.Duration using its built-in String method.
TimeEncoderOfLayout returns TimeEncoder which serializes a time.Time using given layout.
Package-Level Variables (total 11, in which 1 is exported)
DefaultClock is the default clock used by Zap in operations that require time. This clock uses the system clock for all operations.
Package-Level Constants (total 52, in which 45 are exported)
ArrayMarshalerType indicates that the field carries an ArrayMarshaler.
BinaryType indicates that the field carries an opaque binary blob.
BoolType indicates that the field carries a bool.
ByteStringType indicates that the field carries UTF-8 encoded bytes.
Complex128Type indicates that the field carries a complex128.
Complex64Type indicates that the field carries a complex128.
DebugLevel logs are typically voluminous, and are usually disabled in production.
DefaultLineEnding defines the default line ending when writing logs. Alternate line endings specified in EncoderConfig can override this behavior.
DPanicLevel logs are particularly important errors. In development the logger panics after writing the message.
DurationType indicates that the field carries a time.Duration.
ErrorLevel logs are high-priority. If an application is running smoothly, it shouldn't generate any error-level logs.
ErrorType indicates that the field carries an error.
FatalLevel logs a message, then calls os.Exit(1).
Float32Type indicates that the field carries a float32.
Float64Type indicates that the field carries a float64.
InfoLevel is the default logging priority.
InlineMarshalerType indicates that the field carries an ObjectMarshaler that should be inlined.
Int16Type indicates that the field carries an int16.
Int32Type indicates that the field carries an int32.
Int64Type indicates that the field carries an int64.
Int8Type indicates that the field carries an int8.
InvalidLevel is an invalid value for Level. Core implementations may panic if they see messages of this level.
LogDropped indicates that the Sampler dropped a log entry.
LogSampled indicates that the Sampler sampled a log entry.
NamespaceType signals the beginning of an isolated namespace. All subsequent fields should be added to the new namespace.
ObjectMarshalerType indicates that the field carries an ObjectMarshaler.
OmitKey defines the key to use when callers want to remove a key from log output.
PanicLevel logs a message, then panics.
ReflectType indicates that the field carries an interface{}, which should be serialized using reflection.
SkipType indicates that the field is a no-op.
StringerType indicates that the field carries a fmt.Stringer.
StringType indicates that the field carries a string.
TimeFullType indicates that the field carries a time.Time stored as-is.
TimeType indicates that the field carries a time.Time that is representable by a UnixNano() stored as an int64.
Uint16Type indicates that the field carries a uint16.
Uint32Type indicates that the field carries a uint32.
Uint64Type indicates that the field carries a uint64.
Uint8Type indicates that the field carries a uint8.
UintptrType indicates that the field carries a uintptr.
UnknownType is the default field type. Attempting to add it to an encoder will panic.
WarnLevel logs are more important than Info, but don't need individual human review.
WriteThenFatal causes an os.Exit(1) after Write.
WriteThenGoexit runs runtime.Goexit after Write.
WriteThenNoop indicates that nothing special needs to be done. It's the default behavior.
WriteThenPanic causes a panic after Write.