zap: go.uber.org/zap/zaptest/observer Index | Files

package observer

import "go.uber.org/zap/zaptest/observer"

Package observer provides a zapcore.Core that keeps an in-memory, encoding-agnostic repesentation of log entries. It's useful for applications that want to unit test their log output without tying their tests to a particular output encoding.

Index

Package Files

logged_entry.go observer.go

func New Uses

func New(enab zapcore.LevelEnabler) (zapcore.Core, *ObservedLogs)

New creates a new Core that buffers logs in memory (without any encoding). It's particularly useful in tests.

type LoggedEntry Uses

type LoggedEntry struct {
    zapcore.Entry
    Context []zapcore.Field
}

An LoggedEntry is an encoding-agnostic representation of a log message. Field availability is context dependant.

func (LoggedEntry) ContextMap Uses

func (e LoggedEntry) ContextMap() map[string]interface{}

ContextMap returns a map for all fields in Context.

type ObservedLogs Uses

type ObservedLogs struct {
    // contains filtered or unexported fields
}

ObservedLogs is a concurrency-safe, ordered collection of observed logs.

func (*ObservedLogs) All Uses

func (o *ObservedLogs) All() []LoggedEntry

All returns a copy of all the observed logs.

func (*ObservedLogs) AllUntimed Uses

func (o *ObservedLogs) AllUntimed() []LoggedEntry

AllUntimed returns a copy of all the observed logs, but overwrites the observed timestamps with time.Time's zero value. This is useful when making assertions in tests.

func (*ObservedLogs) FilterField Uses

func (o *ObservedLogs) FilterField(field zapcore.Field) *ObservedLogs

FilterField filters entries to those that have the specified field.

func (*ObservedLogs) FilterMessage Uses

func (o *ObservedLogs) FilterMessage(msg string) *ObservedLogs

FilterMessage filters entries to those that have the specified message.

func (*ObservedLogs) FilterMessageSnippet Uses

func (o *ObservedLogs) FilterMessageSnippet(snippet string) *ObservedLogs

FilterMessageSnippet filters entries to those that have a message containing the specified snippet.

func (*ObservedLogs) Len Uses

func (o *ObservedLogs) Len() int

Len returns the number of items in the collection.

func (*ObservedLogs) TakeAll Uses

func (o *ObservedLogs) TakeAll() []LoggedEntry

TakeAll returns a copy of all the observed logs, and truncates the observed slice.

Package observer imports 4 packages (graph) and is imported by 15 packages. Updated 2017-08-22. Refresh now. Tools for package owners.