log

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Overview

Package log provides tools to setup the zerolog logger.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidLevel will be returned when the level given to the WithLevel
	// option is invalid.
	ErrInvalidLevel = errors.New("invalid level")

	// ErrInvalidOutput will be returned when the output writer given to WithOutput
	// is nil.
	ErrInvalidOutput = errors.New("invalid output")
)

Functions

func New

func New(opts ...Option) (*zerolog.Logger, error)

New returns a zerolog.Logger.

func ToLevel

func ToLevel(l string) zerolog.Level

ToLevel translates the given level as a string to a Level.

Types

type Option

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

Option provides for Logger configuration.

func AsDefault

func AsDefault() Option

AsDefault sets the DefaultLogger.

func WithLevel

func WithLevel(level zerolog.Level) Option

WithLevel allows the level to be configured. The default level is LevelInfo.

func WithLevelFieldName

func WithLevelFieldName(name string) Option

WithLevelFieldName allows the customization of the level name. It defaults to "level".

func WithMessageFieldName

func WithMessageFieldName(name string) Option

WithMessageFieldName allows the customization of the message name. It defaults to "message".

func WithOutput

func WithOutput(writer io.Writer) Option

WithOutput allows the format to be configured. The default writer is os.Stdout.

func WithTimestampFieldName

func WithTimestampFieldName(name string) Option

WithTimestampFieldName allows the customization of the timestamp name. It defaults to "time".

func WithoutTimestamp

func WithoutTimestamp() Option

WithoutTimestamp disables the use of a timestamp for logs. Useful for unit tests.

type StringBuffer

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

StringBuffer implements a simple buffer that can be used in tests. It implements the io.WriteCloser interface. Each write will append a string to the Buffer.

func NewStringBuffer

func NewStringBuffer() *StringBuffer

NewStringBuffer returns a StringBuffer.

func SetupTestLogging

func SetupTestLogging(t *testing.T) (context.Context, *StringBuffer)

SetupTestLogging creates a string buffer, a logger that writes to the string buffer and a context which contains the logger.

func (*StringBuffer) Close

func (l *StringBuffer) Close() error

Close allows the string buffer to satisfy the io.WriteCloser interface.

func (*StringBuffer) Index

func (l *StringBuffer) Index(i int) string

Index returns the string at the given index.

func (*StringBuffer) Len

func (l *StringBuffer) Len() int

Len returns the length of the string buffer.

func (*StringBuffer) Write

func (l *StringBuffer) Write(p []byte) (int, error)

Write implements the io.Writer interface.

Jump to

Keyboard shortcuts

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