logs

package
v0.0.0-...-390dfbe Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = defaultLogger

Functions

func CtxDebugf

func CtxDebugf(ctx context.Context, msg string, args ...interface{})

CtxDebugf prints key-value pairs first and then msgs

func CtxDebugw

func CtxDebugw(ctx context.Context, msg string, kvs ...KeyValue)

CtxDebugw prints key-value pairs

func CtxErrorf

func CtxErrorf(ctx context.Context, msg string, args ...interface{})

CtxErrorf prints key-value pairs first and then msgs

func CtxErrorw

func CtxErrorw(ctx context.Context, msg string, kvs ...KeyValue)

CtxErrorw prints key-value pairs

func CtxInfof

func CtxInfof(ctx context.Context, msg string, args ...interface{})

CtxInfof prints key-value pairs first and then msgs

func CtxInfow

func CtxInfow(ctx context.Context, msg string, kvs ...KeyValue)

CtxInfow prints key-value pairs

func CtxLogf

func CtxLogf(ctx context.Context, level Level, msg string, args ...interface{})

CtxLogf prints messages with a specific level

func CtxLogw

func CtxLogw(ctx context.Context, level Level, msg string, kvs ...KeyValue)

CtxLogw prints key-value pairs

func CtxNoticef

func CtxNoticef(ctx context.Context, msg string, args ...interface{})

CtxNoticef prints key-value pairs first and then msgs

func CtxNoticew

func CtxNoticew(ctx context.Context, msg string, kvs ...KeyValue)

CtxNoticew prints key-value pairs

func CtxWarnf

func CtxWarnf(ctx context.Context, msg string, args ...interface{})

CtxWarnf prints key-value pairs first and then msgs

func CtxWarnw

func CtxWarnw(ctx context.Context, msg string, kvs ...KeyValue)

CtxWarnw prints key-value pairs

func CtxWithKVs

func CtxWithKVs(ctx context.Context, kvs ...KeyValue) context.Context

CtxWithKVs append key-value pairs to context

func Debugf

func Debugf(msg string, args ...interface{})

Debugf prints messages with LevelDebug

func Debugw

func Debugw(msg string, kvs ...KeyValue)

Debugw prints key-value pairs

func Errorf

func Errorf(msg string, args ...interface{})

Errorf prints messages with LevelError

func Errorw

func Errorw(msg string, kvs ...KeyValue)

Errorw prints key-value pairs

func Infof

func Infof(msg string, args ...interface{})

Infof prints messages with LevelInfo

func Infow

func Infow(msg string, kvs ...KeyValue)

Infow prints key-value pairs

func Logf

func Logf(level Level, msg string, args ...interface{})

Logf prints messages with a specific level

func Logw

func Logw(level Level, msg string, kvs ...KeyValue)

Logw prints key-value pairs

func Noticef

func Noticef(msg string, args ...interface{})

Noticef prints messages with LevelNotice

func Noticew

func Noticew(msg string, kvs ...KeyValue)

Noticew prints key-value pairs

func Warnf

func Warnf(msg string, args ...interface{})

Warnf prints messages with LevelWarn

func Warnw

func Warnw(msg string, kvs ...KeyValue)

Warnw prints key-value pairs

func WithOption

func WithOption(opts ...Option)

WithOption append options to logger

Types

type KeyValue

type KeyValue struct {
	Key   string
	Value interface{}
}

KeyValue is a key-value pair

func CtxGetKVs

func CtxGetKVs(ctx context.Context) []KeyValue

CtxGetKVs returns key-value pairs from context

func FlatKVs

func FlatKVs(kvis ...interface{}) []KeyValue

FlatKVs returns key-value pairs from flat interface slice

func KV

func KV(key string, value interface{}) KeyValue

func KVCallDepth

func KVCallDepth(key string, depth int) KeyValue

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

func KVDefaultCallDepth

func KVDefaultCallDepth(key string) KeyValue

func KVDefaultTimestamp

func KVDefaultTimestamp(key string) KeyValue

func KVTimestamp

func KVTimestamp(key string, layout string) KeyValue

KVTimestamp returns a timestamp Valuer with a custom time format.

type Level

type Level int
const (
	LevelDebug Level = iota
	LevelInfo
	LevelNotice
	LevelWarn
	LevelError
)

func (Level) String

func (l Level) String() string

type Logger

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

Logger is a logger implementation

func NewLogger

func NewLogger(opts ...Option) *Logger

NewLogger creates a logger with provider

func (*Logger) CtxDebugf

func (l *Logger) CtxDebugf(ctx context.Context, msg string, args ...interface{})

CtxDebugf prints key-value pairs first and then msgs

func (*Logger) CtxDebugw

func (l *Logger) CtxDebugw(ctx context.Context, msg string, kvs ...KeyValue)

CtxDebugw prints key-value pairs

func (*Logger) CtxErrorf

func (l *Logger) CtxErrorf(ctx context.Context, msg string, args ...interface{})

CtxErrorf prints key-value pairs first and then msgs

func (*Logger) CtxErrorw

func (l *Logger) CtxErrorw(ctx context.Context, msg string, kvs ...KeyValue)

CtxErrorw prints key-value pairs

func (*Logger) CtxInfof

func (l *Logger) CtxInfof(ctx context.Context, msg string, args ...interface{})

CtxInfof prints key-value pairs first and then msgs

func (*Logger) CtxInfow

func (l *Logger) CtxInfow(ctx context.Context, msg string, kvs ...KeyValue)

CtxInfow prints key-value pairs

func (*Logger) CtxLogf

func (l *Logger) CtxLogf(ctx context.Context, level Level, msg string, args ...interface{})

CtxLogf prints messages with a specific level

func (*Logger) CtxLogw

func (l *Logger) CtxLogw(ctx context.Context, level Level, msg string, kvs ...KeyValue)

CtxLogw prints key-value pairs

func (*Logger) CtxNoticef

func (l *Logger) CtxNoticef(ctx context.Context, msg string, args ...interface{})

CtxNoticef prints key-value pairs first and then msgs

func (*Logger) CtxNoticew

func (l *Logger) CtxNoticew(ctx context.Context, msg string, kvs ...KeyValue)

CtxNoticew prints key-value pairs

func (*Logger) CtxWarnf

func (l *Logger) CtxWarnf(ctx context.Context, msg string, args ...interface{})

CtxWarnf prints key-value pairs first and then msgs

func (*Logger) CtxWarnw

func (l *Logger) CtxWarnw(ctx context.Context, msg string, kvs ...KeyValue)

CtxWarnw prints key-value pairs

func (*Logger) Debugf

func (l *Logger) Debugf(msg string, args ...interface{})

Debugf prints messages with LevelDebug

func (*Logger) Debugw

func (l *Logger) Debugw(msg string, kvs ...KeyValue)

Debugw prints key-value pairs

func (*Logger) Errorf

func (l *Logger) Errorf(msg string, args ...interface{})

Errorf prints messages with LevelError

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, kvs ...KeyValue)

Errorw prints key-value pairs

func (*Logger) Infof

func (l *Logger) Infof(msg string, args ...interface{})

Infof prints messages with LevelInfo

func (*Logger) Infow

func (l *Logger) Infow(msg string, kvs ...KeyValue)

Infow prints key-value pairs

func (*Logger) Logf

func (l *Logger) Logf(level Level, msg string, args ...interface{})

Logf prints messages with a specific level

func (*Logger) Logw

func (l *Logger) Logw(level Level, msg string, kvs ...KeyValue)

Logw prints key-value pairs

func (*Logger) Noticef

func (l *Logger) Noticef(msg string, args ...interface{})

Noticef prints messages with LevelNotice

func (*Logger) Noticew

func (l *Logger) Noticew(msg string, kvs ...KeyValue)

Noticew prints key-value pairs

func (*Logger) Warnf

func (l *Logger) Warnf(msg string, args ...interface{})

Warnf prints messages with LevelWarn

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, kvs ...KeyValue)

Warnw prints key-value pairs

func (*Logger) WithOption

func (l *Logger) WithOption(opts ...Option) *Logger

WithOption append options to logger

type Option

type Option func(*option)

func WithKVs

func WithKVs(kvs ...KeyValue) Option

WithKVs returns an option that sets default key-value pairs

func WithLevel

func WithLevel(level Level) Option

WithLevel returns an option that filters log level

func WithProvider

func WithProvider(p Provider) Option

WithProvider returns an option that sets a provider

type Provider

type Provider interface {
	Write(level Level, msg string)
}

Provider is the lowest level implementation of log writing

func NewMultiProvider

func NewMultiProvider(s ...Provider) Provider

NewMultiProvider creates a provider that duplicates its writes to all providers

func NewStdProvider

func NewStdProvider() Provider

type Valuer

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

Valuer returns a value

Jump to

Keyboard shortcuts

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