wlog

package
v1.54.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	TypeKey         = "type"
	TimeKey         = "time"
	UIDKey          = "uid"
	SIDKey          = "sid"
	TokenIDKey      = "tokenId"
	OrgIDKey        = "orgId"
	TraceIDKey      = "traceId"
	UnsafeParamsKey = "unsafeParams"
)

Variables

This section is empty.

Functions

func ApplyParams

func ApplyParams(logger LogEntry, params []Param)

func ContextWithOrgID added in v1.41.0

func ContextWithOrgID(ctx context.Context, orgID string) context.Context

func ContextWithSID

func ContextWithSID(ctx context.Context, sid string) context.Context

func ContextWithTokenID

func ContextWithTokenID(ctx context.Context, tokenID string) context.Context

func ContextWithUID

func ContextWithUID(ctx context.Context, uid string) context.Context

func SetDefaultLoggerProvider

func SetDefaultLoggerProvider(provider LoggerProvider)

Types

type AtomicLogLevel added in v1.17.0

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

AtomicLogLevel wraps atomic.Value containing a LogLevel. Always use NewAtomicLogLevel to create it.

func NewAtomicLogLevel added in v1.17.0

func NewAtomicLogLevel(level LogLevel) *AtomicLogLevel

func (*AtomicLogLevel) Enabled added in v1.17.0

func (l *AtomicLogLevel) Enabled(other LogLevel) bool

func (*AtomicLogLevel) Lock added in v1.17.0

func (*AtomicLogLevel) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*AtomicLogLevel) LogLevel added in v1.17.0

func (l *AtomicLogLevel) LogLevel() LogLevel

func (*AtomicLogLevel) SetLevel added in v1.17.0

func (l *AtomicLogLevel) SetLevel(level LogLevel)

func (*AtomicLogLevel) Unlock added in v1.17.0

func (*AtomicLogLevel) Unlock()

type LevelChecker added in v1.17.0

type LevelChecker interface {
	// Enabled determines whether the provided level should be logged.
	// If implemented with LeveledLogger or SetLevel, they must remain consistent with Enabled.
	Enabled(level LogLevel) bool
}

type LeveledLogger

type LeveledLogger interface {
	Debug(msg string, params ...Param)
	Info(msg string, params ...Param)
	Warn(msg string, params ...Param)
	Error(msg string, params ...Param)
	SetLevel(level LogLevel)
}

type LeveledLoggerCreator

type LeveledLoggerCreator func(w io.Writer, level LogLevel) LeveledLogger

type LogEntry

type LogEntry interface {
	StringValue(k, v string)
	OptionalStringValue(k, v string)
	SafeLongValue(k string, v int64)
	IntValue(k string, v int32)
	StringListValue(k string, v []string)
	StringMapValue(k string, v map[string]string)
	AnyMapValue(k string, v map[string]interface{})

	// ObjectValue logs the provided value associated with the specified key. If marshalerType is non-nil, then if a
	// custom marshaler is registered for that type, it may be used to log the entry. If marshalerType is nil or no
	// marshaler is registered for the provided type, the entry should be logged using reflection.
	ObjectValue(k string, v interface{}, marshalerType reflect.Type)
}

type LogLevel

type LogLevel string
const (
	DebugLevel LogLevel = "debug"
	InfoLevel  LogLevel = "info"
	WarnLevel  LogLevel = "warn"
	ErrorLevel LogLevel = "error"
	FatalLevel LogLevel = "fatal"
)

func (LogLevel) Enabled added in v1.17.0

func (l LogLevel) Enabled(other LogLevel) bool

func (*LogLevel) UnmarshalText added in v1.3.0

func (l *LogLevel) UnmarshalText(b []byte) error

type Logger

type Logger interface {
	Log(params ...Param)
}

type LoggerCreator

type LoggerCreator func(w io.Writer) Logger

type LoggerProvider

type LoggerProvider interface {
	NewLogger(w io.Writer) Logger
	NewLeveledLogger(w io.Writer, level LogLevel) LeveledLogger
}

func DefaultLoggerProvider

func DefaultLoggerProvider() LoggerProvider

func NewJSONMarshalLoggerProvider

func NewJSONMarshalLoggerProvider() LoggerProvider

NewJSONMarshalLoggerProvider returns a new logger provider that uses a MapLogEntry as its log entry and performs logging by performing a json.Marshal of the MapLogEntry. This is a naive implementation that is not very efficient: its primary purpose is for tests and in-memory usage in scenarios where one does not want to use a logger provider that uses an external library.

func NewNoopLoggerProvider

func NewNoopLoggerProvider() LoggerProvider

NewNoopLoggerProvider returns a LoggerProvider whose implementations are no-ops. That is, they return immediately after doing nothing.

type MapLogEntry

type MapLogEntry interface {
	LogEntry

	StringValues() map[string]string
	SafeLongValues() map[string]int64
	IntValues() map[string]int32
	StringListValues() map[string][]string
	StringMapValues() map[string]map[string]string
	AnyMapValues() map[string]map[string]interface{}
	ObjectValues() map[string]ObjectValue

	// Apply applies the values of all of the stored entries of this MapLogEntry to the provided LogEntry.
	Apply(logEntry LogEntry)
	// AllValues returns a single map that contains all of the keys and values stored in this entry.
	AllValues() map[string]interface{}
}

func NewMapLogEntry

func NewMapLogEntry() MapLogEntry

type MapValueEntries

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

func (*MapValueEntries) AnyMapValue

func (m *MapValueEntries) AnyMapValue(key string, values map[string]interface{})

func (*MapValueEntries) AnyMapValues

func (m *MapValueEntries) AnyMapValues() map[string]map[string]interface{}

func (*MapValueEntries) StringMapValue

func (m *MapValueEntries) StringMapValue(key string, values map[string]string)

func (*MapValueEntries) StringMapValues

func (m *MapValueEntries) StringMapValues() map[string]map[string]string

type ObjectValue

type ObjectValue struct {
	Value         interface{}
	MarshalerType reflect.Type
}

type Param

type Param interface {
	// contains filtered or unexported methods
}

func Int64Param

func Int64Param(key string, value int64) Param

func IntParam

func IntParam(key string, value int32) Param

func NewParam

func NewParam(fn func(entry LogEntry)) Param

func OptionalStringParam

func OptionalStringParam(key, value string) Param

func ParamsWithMessage added in v1.11.0

func ParamsWithMessage(msg string, params []Param) []Param

ParamsWithMessage returns a new slice that appends a StringParam with the key "message" and value of the provided msg parameter if it is non-empty. If msg is empty, returns the provided slice without modification.

func StringParam

func StringParam(key, value string) Param

Jump to

Keyboard shortcuts

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