logit

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 11 Imported by: 0

README

helper -> filter -> wLogger

Documentation

Index

Constants

View Source
const LevelKey = "level"

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())
View Source
var DefaultMessageKey = "type"

DefaultMessageKey default message key.

Functions

func Debug

func Debug(a ...interface{})

Debug logs a message at debug level.

func DebugF

func DebugF(format string, a ...interface{})

DebugF logs a message at debug level.

func DebugW

func DebugW(keyValues ...interface{})

DebugW logs a message at debug level.

func Error

func Error(a ...interface{})

Error logs a message at error level.

func ErrorF

func ErrorF(format string, a ...interface{})

ErrorF logs a message at error level.

func ErrorW

func ErrorW(keyValues ...interface{})

ErrorW logs a message at error level.

func Fatal

func Fatal(a ...interface{})

Fatal logs a message at fatal level.

func FatalF

func FatalF(format string, a ...interface{})

FatalF logs a message at fatal level.

func FatalW

func FatalW(keyValues ...interface{})

FatalW logs a message at fatal level.

func Info

func Info(a ...interface{})

Info logs a message at info level.

func InfoF

func InfoF(format string, a ...interface{})

InfoF logs a message at info level.

func InfoW

func InfoW(keyValues ...interface{})

InfoW logs a message at info level.

func Log

func Log(level Level, keyValues ...interface{}) error

Log Print logit by level and keyValues.

func SetLogger

func SetLogger(logger Logger)

func Value

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

Value return the function value.

func Warn

func Warn(a ...interface{})

Warn logs a message at warn level.

func WarnF

func WarnF(format string, a ...interface{})

WarnF logs a message at warn level.

func WarnW

func WarnW(keyValues ...interface{})

WarnW logs a message at warn level.

Types

type Filter

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

Filter is a logger filter.

func NewFilter

func NewFilter(logger Logger, opts ...FilterOption) *Filter

NewFilter new a logger filter.

func (*Filter) Log

func (f *Filter) Log(level Level, keyValues ...interface{}) error

Log Print logit by level and keyValues

type FilterOption

type FilterOption func(*Filter)

FilterOption is filter option.

func FilterFunc

func FilterFunc(f func(level Level, keyValues ...interface{}) bool) FilterOption

FilterFunc with filter func.

func FilterKey

func FilterKey(keys ...string) FilterOption

FilterKey with filter key.

func FilterLevel

func FilterLevel(level Level) FilterOption

FilterLevel with filter level.

func FilterValue

func FilterValue(values ...string) FilterOption

FilterValue with filter value.

type Helper

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

Helper is a logger helper.

func Context

func Context(ctx context.Context) *Helper

Context with context logger.

func GetGlobalHelper

func GetGlobalHelper() *Helper

func NewHelper

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

NewHelper new a logger helper.

func (*Helper) Debug

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

Debug logs a message at debug level.

func (*Helper) DebugF

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

DebugF logs a message at debug level.

func (*Helper) DebugW

func (h *Helper) DebugW(keyValues ...interface{})

DebugW logs a message at debug level.

func (*Helper) Enabled

func (h *Helper) Enabled(level Level) bool

Enabled returns true if the given level above this level. It delegates to the underlying *Filter.

func (*Helper) Error

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

Error logs a message at error level.

func (*Helper) ErrorF

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

ErrorF logs a message at error level.

func (*Helper) ErrorW

func (h *Helper) ErrorW(keyValues ...interface{})

ErrorW logs a message at error level.

func (*Helper) Fatal

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

Fatal logs a message at fatal level.

func (*Helper) FatalF

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

FatalF logs a message at fatal level.

func (*Helper) FatalW

func (h *Helper) FatalW(keyValues ...interface{})

FatalW logs a message at fatal level.

func (*Helper) Info

func (h *Helper) Info(a ...interface{})

Info logs a message at info level.

func (*Helper) InfoF

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

InfoF logs a message at info level.

func (*Helper) InfoW

func (h *Helper) InfoW(keyValues ...interface{})

InfoW logs a message at info level.

func (*Helper) Log

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

Log Print logit by level and keyValues

func (*Helper) Warn

func (h *Helper) Warn(a ...interface{})

Warn logs a message at warn level.

func (*Helper) WarnF

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

WarnF logs a message at warn level.

func (*Helper) WarnW

func (h *Helper) WarnW(keyValues ...interface{})

WarnW logs a message at warn level.

func (*Helper) WithContext

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

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

func (*Helper) WithValues

func (h *Helper) WithValues(kv ...interface{}) *Helper

type HelperOption

type HelperOption func(*Helper)

HelperOption is Helper option.

func WithMessageKey

func WithMessageKey(k string) HelperOption

WithMessageKey with message key.

func WithSprint

func WithSprint(sprint func(...interface{}) string) HelperOption

WithSprint with sprint

func WithSprintf

func WithSprintf(sprintf func(format string, a ...interface{}) string) HelperOption

WithSprintf with sprintf

type Level

type Level int8
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

func (Level) Key

func (l Level) Key() string

func (Level) String

func (l Level) String() string

type Logger

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

func NewStdLogger

func NewStdLogger(w io.Writer) Logger

func With

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

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 logit 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