zaplg

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package zaplg adapts Uber's zap logging library for use with the lg interface.

Index

Constants

This section is empty.

Variables

View Source
var TestingFactoryFn = func(w io.Writer) lg.Log {

	return NewWith(w, testingFormat, true, true, true, 1)
}

TestingFactoryFn can be passed to testlg.NewWith to use zap as the backing impl.

Functions

func FuncCallerEncoder added in v0.3.0

func FuncCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)

FuncCallerEncoder extends zapcore.ShortCallerEncoder to also include the calling function name. That is, it serializes the caller in package/file:line:func format, trimming all but the final directory from the full path. This implementation is probably not very efficient, so use with caution.

func TestingCallerEncoder added in v0.3.0

func TestingCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)

TestingCallerEncoder serializes the caller in package.func format. This is especially useful when working with the testing framework: t.Log etc already report file:line. This implementation is probably not very efficient, so use with caution.

Types

type Log

type Log struct {
	*zap.SugaredLogger
}

Log implements lg.Log.

func New

func New() *Log

New returns a Log that writes to os.Stdout in text format, reporting the timestamp, level, and caller.

func NewWith

func NewWith(w io.Writer, format string, timestamp, level, caller bool, addCallerSkip int) *Log

NewWith returns a Log that writes to w. Format should be one of "json", "text", or "testing"; defaults to "text". The timestamp, level and caller params determine if those fields are reported. The addCallerSkip param is used to to adjust the frame reported as the caller.

Use NewWithZap if more control over output options is desired.

func NewWithZap

func NewWithZap(zlogger *zap.Logger) *Log

NewWithZap returns a Log backed by zlogger.

func (*Log) WarnIfCloseError

func (l *Log) WarnIfCloseError(c io.Closer)

func (*Log) WarnIfError

func (l *Log) WarnIfError(err error)

func (*Log) WarnIfFuncError

func (l *Log) WarnIfFuncError(fn func() error)

Jump to

Keyboard shortcuts

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