logger

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 12 Imported by: 1

README

logger

Usage

go get github.com/jacexh/gopkg/logger

Documentation

Index

Constants

View Source
const (
	DefaultMessageKey = "msg"
	DefaultLevel      = Info
)

Variables

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 keyvalues slices with odd length to substitute the missing value.
	ErrMissingValue = errors.New("(missing value)")
)

Functions

This section is empty.

Types

type Helper

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

func NewHelper

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

func (*Helper) Debug

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

func (*Helper) Debugf

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

func (*Helper) Error

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

func (*Helper) Errorf

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

func (*Helper) Fatal

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

func (*Helper) Fatalf

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

func (*Helper) Info

func (h *Helper) Info(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(keyvals ...interface{})

func (*Helper) Panicf

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

func (*Helper) Warn

func (h *Helper) Warn(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.

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