zaprec

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 3 Imported by: 0

README

zaprec

made-with-Go Go GitHub go.mod Go version GoReportCard example codecov GitHub issues GitHub code size in bytes

Recording of log-calls to zap.Logger (see uber-go/zap). This package is intended to be used for easier testing of logging with zap.

Installation

In order to use this package, run:

go get github.com/lefinal/zaprec

Usage

Create a new recorder via:

logger, rec := NewRecorder(zapcore.InfoLevel)

You can now use logger as regular *zap.Logger and check the returned record store for records with methods like Records() or RecordsByLevel(level zapcore.Level).

Documentation

Overview

Package zaprec allows recording of log-calls to zap.Logger. This is especially useful in tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Record

type Record struct {
	// Entry is the zapcore.Entry to be logged.
	Entry zapcore.Entry
	// Fields are all passed fields in the Write-call.
	Fields []zapcore.Field
}

Record holds all data that is recorded by recorder in recorder.Write-calls. Keep in mind that everything is kept as direct reference.

type RecordStore

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

RecordStore holds a Record list allowing centralized collection of records.

func NewRecorder

func NewRecorder(levelEnabler zapcore.LevelEnabler) (*zap.Logger, *RecordStore)

NewRecorder creates and initializes a new recorder with the given zapcore.LevelEnabler. The returned zap.Logger records all entries to the returned RecordStore.

func (*RecordStore) Dump added in v1.1.0

func (rs *RecordStore) Dump()

Dump all contents to stdout. Useful for test logs if tests failed.

func (*RecordStore) DumpToLogger added in v1.1.0

func (rs *RecordStore) DumpToLogger(logger *zap.Logger)

DumpToLogger dumps all records to the given zap.Logger.

func (*RecordStore) Records

func (rs *RecordStore) Records() []Record

Records returns a copy of the list of records.

func (*RecordStore) RecordsByLevel

func (rs *RecordStore) RecordsByLevel(level zapcore.Level) []Record

RecordsByLevel returns all records that match the given zapcore.Level.

Jump to

Keyboard shortcuts

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