logger

package
v0.5.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMessageKey = "msg"
	DefaultLevel      = Info
)
View Source
var (
	// DefaultCaller is a Valuer that returns the file and line where the Log method was invoked.
	// It can only be used with log.With.
	DefaultCaller = Caller(3)
)
View Source
var (
	// ErrMissingValue is appended to key-values slices with odd length to substitute the missing value.
	ErrMissingValue = errors.New("(missing value)")
)

Functions

func InContext added in v0.2.0

func InContext(ctx context.Context, log Logger) context.Context

InContext 将Logger存入Context。

func SetDefault added in v0.2.3

func SetDefault(fn func() Logger)

Types

type Helper deprecated

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

Deprecated: Please use log/slog instead of this module.

func FromContextAsHelper added in v0.2.3

func FromContextAsHelper(ctx context.Context) *Helper

FromContextAsHelper 从Context中提取Logger,返回Helper对象。

func NewHelper

func NewHelper(logger Logger, opts ...Option) *Helper

func (*Helper) Debug

func (h *Helper) Debug(msg string, keyvals ...interface{})

func (*Helper) Debugf

func (h *Helper) Debugf(format string, a ...interface{})

func (*Helper) Error

func (h *Helper) Error(msg string, keyvals ...interface{})

func (*Helper) Errorf

func (h *Helper) Errorf(format string, a ...interface{})

func (*Helper) Fatal

func (h *Helper) Fatal(msg string, keyvals ...interface{})

func (*Helper) Fatalf

func (h *Helper) Fatalf(format string, a ...interface{})

func (*Helper) Info

func (h *Helper) Info(msg string, keyvals ...interface{})

func (*Helper) Infof

func (h *Helper) Infof(format string, a ...interface{})

func (*Helper) Log

func (h *Helper) Log(level Level, keyvals ...interface{})

func (*Helper) Panic

func (h *Helper) Panic(msg string, keyvals ...interface{})

func (*Helper) Panicf

func (h *Helper) Panicf(format string, a ...interface{})

func (*Helper) Warn

func (h *Helper) Warn(msg string, keyvals ...interface{})

func (*Helper) Warnf

func (h *Helper) Warnf(format string, a ...interface{})

func (*Helper) WithContext

func (h *Helper) WithContext(ctx context.Context) *Helper

type Level

type Level int

Level 日志等级定义.

const (
	Debug Level = iota
	Info
	Warn
	Error
	Panic
	Fatal
)

type Logger

type Logger interface {
	Log(level Level, keyvals ...interface{})
}

Logger is the fundamental interface for all log operations. Log creates a log event from keyvals, a variadic sequence of alternating keys and values. Implementations must be safe for concurrent use by multiple goroutines. In particular, any implementation of Logger that appends to keyvals or modifies or retains any of its elements must make a copy first. Deprecated: Please use log/slog instead of this module.

func Default added in v0.2.0

func Default() Logger

func FromContext added in v0.2.0

func FromContext(ctx context.Context) Logger

FromContext 从Context中提取Logger,如果不存在则返回默认的Logger。

func NewStdLogger

func NewStdLogger(output io.Writer) Logger

NewStdLogger new a logger implements Logger interface.

func With

func With(l Logger, keyvals ...interface{}) Logger

func WithContext

func WithContext(ctx context.Context, l Logger) Logger

type Option

type Option func(*Helper)

func WithLevel

func WithLevel(level Level) Option

func WithMessageKey

func WithMessageKey(key string) Option

type Valuer

type Valuer func(context.Context) interface{}

A Valuer generates a log value. When passed to With, WithPrefix in a value element (odd indexes), it represents a dynamic value which is re-evaluated with each log event.

func Caller

func Caller(depth int) Valuer

Jump to

Keyboard shortcuts

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