log

package
v2.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttrKeyTime             = "time"
	AttrKeySpanID           = "span_id"
	AttrKeyTraceID          = "trace_id"
	AttrKeyTraceFlags       = "trace_flags"
	AttrKeySource           = "source"
	AttrKeyError            = "error"
	AttrKeyMsg              = "msg"
	AttrKeyLevel            = "level"
	AttrKeyStack            = "stack"
	AttrKeyLoggerName       = "logger_name"
	AttrKeyCallerSkipOffset = "caller_skip_offset"
	AttrKeyCallerPC         = "caller_pc"
	AttrKeySpan             = "span"
)
View Source
const (
	LevelNameTrace = "trace"
	LevelNameDebug = "debug"
	LevelNameInfo  = "info"
	LevelNameWarn  = "warn"
	LevelNameError = "error"
	LevelNamePanic = "panic"
	LevelNameFatal = "fatal"
)

Variables

View Source
var (
	AttrTime             = TimeKey(AttrKeyTime)
	AttrSpanID           = StringKey(AttrKeySpanID)
	AttrTraceID          = StringKey(AttrKeyTraceID)
	AttrTraceFlags       = IntKey(AttrKeyTraceFlags)
	AttrSource           = StringKey(AttrKeySource)
	AttrMsg              = StringKey(AttrKeyMsg)
	AttrLevel            = StringKey(AttrKeyLevel)
	AttrStack            = StringKey(AttrKeyStack)
	AttrLoggerName       = StringKey(AttrKeyLoggerName)
	AttrCallerSkipOffset = IntKey(AttrKeyCallerSkipOffset)
	AttrCallerPC         = Int64Key(AttrKeyCallerPC)
)
View Source
var (
	EmptyAttr     = Attr{}
	Any           = slog.Any
	AnyValue      = slog.AnyValue
	String        = slog.String
	StringValue   = slog.StringValue
	Int64         = slog.Int64
	Int64Value    = slog.Int64Value
	Int           = slog.Int
	IntValue      = slog.IntValue
	Uint64        = slog.Uint64
	Uint64Value   = slog.Uint64Value
	Float64       = slog.Float64
	Float64Value  = slog.Float64Value
	Bool          = slog.Bool
	BoolValue     = slog.BoolValue
	Time          = slog.Time
	TimeValue     = slog.TimeValue
	Duration      = slog.Duration
	DurationValue = slog.DurationValue
	Group         = slog.Group
	GroupValue    = slog.GroupValue
)
View Source
var (
	LevelTrace = slog.Level(-8)
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
	LevelPanic = slog.Level(12)
	LevelFatal = slog.Level(16)
)
View Source
var (
	KindAny       = slog.KindAny
	KindBool      = slog.KindBool
	KindDuration  = slog.KindDuration
	KindFloat64   = slog.KindFloat64
	KindInt64     = slog.KindInt64
	KindString    = slog.KindString
	KindTime      = slog.KindTime
	KindUint64    = slog.KindUint64
	KindGroup     = slog.KindGroup
	KindLogValuer = slog.KindLogValuer
)
View Source
var (
	IgnorePC  bool
	AddSource = true
)
View Source
var (
	NewRecord = slog.NewRecord
)

Functions

func AnyAttrs

func AnyAttrs(attrs []Attr) []any

func AnyKey

func AnyKey(key string) func(any) Attr

func AttrKey

func AttrKey[K, V any](factory func(K, V) Attr, key K) func(V) Attr

func BoolKey

func BoolKey(key string) func(bool) Attr

func DurationKey

func DurationKey(key string) func(time.Duration) Attr

func Float64Key

func Float64Key(key string) func(float64) Attr

func IndexLevel

func IndexLevel(l Level) int

IndexLevel required simplification

func Int64Key

func Int64Key(key string) func(int64) Attr

func IntKey

func IntKey(key string) func(int) Attr

func StringKey

func StringKey(key string) func(string) Attr

func StringLevel

func StringLevel(l Level) string

func TimeKey

func TimeKey(key string) func(time.Time) Attr

func ToGrpcLoggerV2

func ToGrpcLoggerV2(logger Logger) grpclog.LoggerV2

func ToLogr

func ToLogr(logger Logger) logr.Logger

func ToTraceLog

func ToTraceLog(logger Logger) tracelog.Logger

func ToZap

func ToZap(logger Logger) *zap.Logger

func Uint64Key

func Uint64Key(key string) func(uint64) Attr

func ZapCtx

func ZapCtx(ctx context.Context) zap.Field

func ZapSpan

func ZapSpan(span trace.Span) zap.Field

Types

type Attr

type Attr = slog.Attr

func Error

func Error(err error) Attr

func NamedError

func NamedError(name string, err error) Attr

func SliceAttrs

func SliceAttrs(attrs map[string]Attr) []Attr

func Span

func Span(span trace.Span) Attr

func Stack

func Stack(err error) Attr

type EchoHandler

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

func NewEchoHandler

func NewEchoHandler(ch chan Record) *EchoHandler

func (*EchoHandler) Enabled

func (h *EchoHandler) Enabled(context.Context, Level) bool

func (*EchoHandler) Handle

func (h *EchoHandler) Handle(ctx context.Context, rec Record) error

func (*EchoHandler) WithAttrs

func (h *EchoHandler) WithAttrs(attrs []Attr) Handler

func (*EchoHandler) WithGroup

func (h *EchoHandler) WithGroup(name string) Handler

type Handler

type Handler = slog.Handler

func NewSampler

func NewSampler(handler Handler, tick time.Duration, threshold, thereafter int, options ...SamplerOption) Handler

func NewTeeHandler

func NewTeeHandler(handler Handler, other ...Handler) Handler

type JSONHandler

type JSONHandler = slog.JSONHandler

func NewJSONHandler

func NewJSONHandler(minLevel slog.Leveler, replacerAttrs ...ReplacerAttr) *JSONHandler

type Level

type Level = slog.Level

func UnmarshalTextLevel

func UnmarshalTextLevel(s string) Level

type Leveler

type Leveler = slog.Leveler

type LogProvider

type LogProvider interface {
	Logger() Logger
}

type LogValuer

type LogValuer = slog.LogValuer //nolint:revive,golint

type Logger

type Logger interface {
	LogAttrs(ctx context.Context, level Level, msg string, attrs ...Attr)
	Enabled(Level) bool
	Debug(ctx context.Context, msg string, attrs ...Attr)
	Info(ctx context.Context, msg string, attrs ...Attr)
	Warn(ctx context.Context, msg string, attrs ...Attr)
	Error(ctx context.Context, msg string, attrs ...Attr)
	Panic(ctx context.Context, msg string, attrs ...Attr)
	Fatal(ctx context.Context, msg string, attrs ...Attr)
	With(attrs ...Attr) Logger
	Named(string) Logger
	NewContext(ctx context.Context) context.Context
	For(ctx context.Context) Logger
	ForSpan(span trace.Span) Logger
	Attrs() []Attr
	Span() trace.Span
	Handler() Handler
}

func NewLogger

func NewLogger(hs ...Handler) Logger

func NewTextLogger

func NewTextLogger(minLevel Leveler) Logger

type LoggerCtx

type LoggerCtx struct {
	context.Context

	Span  trace.Span
	Attrs []Attr
}

func AppendLoggerCtx

func AppendLoggerCtx(ctx context.Context, span trace.Span, attrs ...Attr) *LoggerCtx

func LoggerCtxFrom

func LoggerCtxFrom(ctx context.Context) *LoggerCtx

func NewLoggerCtx

func NewLoggerCtx(ctx context.Context, span trace.Span, attrs ...Attr) *LoggerCtx

func (*LoggerCtx) Value

func (c *LoggerCtx) Value(key any) any

type Record

type Record = slog.Record

type ReplacerAttr

type ReplacerAttr func([]string, Attr) Attr

func ChainReplacerAttrs

func ChainReplacerAttrs(replacers []ReplacerAttr) ReplacerAttr

type SamplerOption

type SamplerOption func(*sampler)

func WithSamplerLevelThreshold

func WithSamplerLevelThreshold(level Level, n uint64) SamplerOption

func WithSamplerLevelThresholdString

func WithSamplerLevelThresholdString(str string) SamplerOption

type Source

type Source = slog.Source

type TextHandler

type TextHandler = slog.TextHandler

func NewTextHandler

func NewTextHandler(minLevel slog.Leveler, replacerAttrs ...ReplacerAttr) *TextHandler

type Value

type Value = slog.Value

type WriteThenAction

type WriteThenAction int
const (
	WriteThenUnspecified WriteThenAction = iota
	WriteThenNoop
	WriteThenPanic
	WriteThenFatal
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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