ztest

package
v0.0.0-...-bd62367 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ztest provides a variety of helpers for testing log output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElapsedSecondsTimeEncoder

func ElapsedSecondsTimeEncoder(start time.Time) zapcore.TimeEncoder

func NewLogger

func NewLogger(t zaptest.TestingT, opts ...LoggerOption) *zap.Logger

NewLogger builds a new Logger that logs all messages to the given testing.TB.

logger := ztest.NewLogger(t)

Use this with a *testing.T or *testing.B to get logs which get printed only if a test fails or if you ran go test -v.

The returned logger defaults to logging debug level messages and above. This may be changed by passing a ztest.Level during construction.

logger := ztest.NewLogger(t, ztest.Level(zap.WarnLevel))

You may also pass zap.Option's to customize test logger.

logger := ztest.NewLogger(t, ztest.WrapOptions(zap.AddCaller()))

func ShortLevelEncoder

func ShortLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

ShortLevelEncoder encodes level as single letter.

Types

type LoggerOption

type LoggerOption interface {
	// contains filtered or unexported methods
}

LoggerOption configures the test logger built by NewLogger.

func Level

func Level(enab zapcore.LevelEnabler) LoggerOption

Level controls which messages are logged by a test Logger built by NewLogger.

func WrapOptions

func WrapOptions(zapOpts ...zap.Option) LoggerOption

WrapOptions adds zap.Option's to a test Logger built by NewLogger.

Jump to

Keyboard shortcuts

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