log

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 12 Imported by: 0

README

helper -> filter -> wLogger

Documentation

Index

Constants

View Source
const (
	DefaultMessageKey          = "type"
	DefaultLogIdKey            = "logId"
	DefaultCallerKey           = "caller"
	DefaultDownstreamKey       = "downstream"
	DefaultConcurrencyLogIdKey = "concurrencyLogId"
	DefaultWebSocketUUIDKey    = "websocketUUID"
	DefaultWebSocketLogIdKey   = "websocketLogId"
	DefaultCronActionKey       = "cronAction"
	DefaultWebSocketPathKey    = "websocketPath"
)
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())

Functions

func Value

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

Value return the function value.

Types

type Filter

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

Filter is a zaplogger filter.

func NewFilter

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

NewFilter new a zaplogger filter.

func (*Filter) Log

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

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.

type Helper

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

func NewHelper

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

func (*Helper) Debug

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

func (*Helper) DebugF

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

func (*Helper) DebugW

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

func (*Helper) Error

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

func (*Helper) ErrorF

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

func (*Helper) ErrorW

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

func (*Helper) Fatal

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

func (*Helper) FatalF

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

func (*Helper) FatalW

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

func (*Helper) Info

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

func (*Helper) InfoF

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

func (*Helper) InfoW

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

func (*Helper) Log

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

func (*Helper) Warn

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

func (*Helper) WarnF

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

func (*Helper) WarnW

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

func (*Helper) WithContext

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

func (*Helper) WithValues

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

type HelperOption

type HelperOption func(*Helper)

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 zaplogger debug level.
	LevelDebug Level = iota - 1
	// LevelInfo is zaplogger info level.
	LevelInfo
	// LevelWarn is zaplogger warn level.
	LevelWarn
	// LevelError is zaplogger error level.
	LevelError
	// LevelFatal is zaplogger 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 zaplogger 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 FileWithLineNumCaller

func FileWithLineNumCaller() Valuer

func FileWithLineNumCallerRedis

func FileWithLineNumCallerRedis() Valuer

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