statz

package
v0.0.62 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscardLogger

func DiscardLogger(_ context.Context, _ Level, _ *status.Status, _ error)

DiscardLogger is a logger to discard logs. If you want to disable logging, assign DiscardLogger to DefaultLogger.

func New

func New(ctx context.Context, level Level, code codes.Code, msg string, err error, opts ...ErrorOption) error

New is a function like errors.New() for gRPC status.Status.

The location where statz.New() is called is logged by DefaultLogger.

Types

type ErrorOption

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

func WithDetails

func WithDetails(details ...protoiface.MessageV1) ErrorOption

func WithLogger

func WithLogger(handler Logger) ErrorOption

type Level

type Level string
const (
	DebugLevel Level = "DEBUG"
	InfoLevel  Level = "INFO"
	WarnLevel  Level = "WARN"
	ErrorLevel Level = "ERROR"
)

type Logger

type Logger = func(ctx context.Context, level Level, stat *status.Status, err error)
var (
	// DefaultLogger is a logger to record the location of statz.New() calls.
	DefaultLogger Logger = func(_ context.Context, level Level, stat *status.Status, err error) {
		_, file, line, _ := runtime.Caller(2)
		log.Printf("level=%s caller=%s:%d code=%s message=%q details=%s error=%q stacktrace=%q", level, filepathz.Short(file), line, stat.Code(), stat.Message(), stat.Details(), fmt.Sprintf("%v", err), fmt.Sprintf("%+v", err))
	}
)

Jump to

Keyboard shortcuts

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