wlog

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func ApplyParams

func ApplyParams(logger LogEntry, params []Param)

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