spy

package
v0.0.0-...-3a27902 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2016 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package spy provides an implementation of zap.Logger that helps test logging wrappers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...zap.Option) (*Logger, *Sink)

New constructs a spy logger that collects spy.Log records to a Sink. It returns the logger and its sink.

Options can change things like log level and initial fields, but any output related options will not be honored.

Types

type Log

type Log struct {
	Level  zap.Level
	Msg    string
	Fields []zap.Field
}

A Log is an encoding-agnostic representation of a log message.

type Logger

type Logger struct {
	sync.Mutex
	zap.Meta
	// contains filtered or unexported fields
}

Logger satisfies zap.Logger, but makes testing convenient.

func (*Logger) Check

func (l *Logger) Check(lvl zap.Level, msg string) *zap.CheckedMessage

Check returns a CheckedMessage if logging a particular message would succeed.

func (*Logger) DFatal

func (l *Logger) DFatal(msg string, fields ...zap.Field)

DFatal logs at the Fatal level if the development flag is set, and the Error level otherwise.

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zap.Field)

Debug logs at the Debug level.

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...zap.Field)

Error logs at the Error level.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...zap.Field)

Fatal logs at the Fatal level. Note that the spy logger doesn't actuall call os.Exit.

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zap.Field)

Info logs at the Info level.

func (*Logger) Log

func (l *Logger) Log(lvl zap.Level, msg string, fields ...zap.Field)

Log writes a message at the specified level.

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...zap.Field)

Panic logs at the Panic level. Note that the spy Logger doesn't actually panic.

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zap.Field)

Warn logs at the Warn level.

func (*Logger) With

func (l *Logger) With(fields ...zap.Field) zap.Logger

With creates a new Logger with additional fields added to the logging context.

type Sink

type Sink struct {
	sync.Mutex
	// contains filtered or unexported fields
}

A Sink stores Log structs.

func (*Sink) Logs

func (s *Sink) Logs() []Log

Logs returns a copy of the sink's accumulated logs.

func (*Sink) WriteLog

func (s *Sink) WriteLog(lvl zap.Level, msg string, fields []zap.Field)

WriteLog writes a log message to the LogSink.

Jump to

Keyboard shortcuts

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