xlogger

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const LevelKey = "level"

LevelKey is logger level key.

Variables

View Source
var (
	// DefaultCaller is a Valuer that returns the file and line.
	DefaultCaller = Caller(4)

	// DefaultTimestamp is a Valuer that returns the current wallclock time.
	DefaultTimestamp = Timestamp(time.RFC3339)
)
View Source
var DefaultLogger = NewStdLogger(log.Writer())

DefaultLogger is default logger.

Functions

func Value

func Value(ctx context.Context, v interface{}) interface{}

Value return the function value.

Types

type Level

type Level int8

Level is a logger level.

const (
	// LevelDebug is logger debug level.
	LevelDebug Level = iota - 1
	// LevelInfo is logger info level.
	LevelInfo
	// LevelWarn is logger warn level.
	LevelWarn
	// LevelError is logger error level.
	LevelError
	// LevelFatal is logger fatal level
	LevelFatal
)

func ParseLevel

func ParseLevel(s string) Level

ParseLevel parses a level string into a logger Level value.

func (Level) Key

func (l Level) Key() string

func (Level) String

func (l Level) String() string

type Logger

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

Logger is a logger interface.

func NewStdLogger

func NewStdLogger(w io.Writer) Logger

NewStdLogger new a logger with writer.

func With

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

With with logger fields.

func WithContext

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

WithContext returns a shallow copy of l with its context changed to ctx. The provided ctx must be non-nil.

type Valuer

type Valuer func(ctx context.Context) interface{}

Valuer is returns a log value.

func Caller

func Caller(depth int) Valuer

Caller returns a Valuer that returns a pkg/file:line description of the caller.

func Timestamp

func Timestamp(layout string) Valuer

Timestamp returns a timestamp Valuer with a custom time format.

Jump to

Keyboard shortcuts

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