slog

package
v0.0.0-...-27647ab Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: BSD-3-Clause Imports: 10 Imported by: 9

Documentation

Index

Constants

View Source
const (
	TimeKey    = slog.TimeKey
	LevelKey   = slog.LevelKey
	MessageKey = slog.MessageKey
	SourceKey  = slog.SourceKey
)
View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)
View Source
const (
	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
const BadKey = "!BADKEY"
View Source
const ErrorKey = "error"
View Source
const ErrorMsg = "error"
View Source
const PanicKey = "panic"

Variables

View Source
var IgnorePC = false

Functions

func AsStdHandler

func AsStdHandler(h Handler) stdslog.Handler

func Debug

func Debug(msg string, args ...any)

func DebugCtx

func DebugCtx(ctx context.Context, msg string, args ...any)

func Error

func Error(msg string, args ...any)

func ErrorCtx

func ErrorCtx(ctx context.Context, msg string, args ...any)

func Fatal

func Fatal(obj any, args ...any)

func Fatalf

func Fatalf(format string, v ...any)

func Fatalln

func Fatalln(v ...any)

func IfError

func IfError(err error, args ...any)

func IfFatal

func IfFatal(err error, args ...any)

func IfPanic

func IfPanic(err error, args ...any)

func Info

func Info(msg string, args ...any)

func InfoCtx

func InfoCtx(ctx context.Context, msg string, args ...any)

func InstallOldWriter

func InstallOldWriter(o *old.Logger, l Logger, level Level)

func Log

func Log(ctx context.Context, level Level, msg string, args ...any)

func LogAttrs

func LogAttrs(ctx context.Context, level Level, msg string, attrs ...Attr)

func OrError

func OrError(fn func() error, args ...any)

func OrFatal

func OrFatal(fn func() error, args ...any)

func OrPanic

func OrPanic(fn func() error, args ...any)

func Panic

func Panic(obj any, args ...any)

func Panicf

func Panicf(format string, v ...any)

func Panicln

func Panicln(v ...any)

func Print

func Print(v ...any)

func Printf

func Printf(format string, v ...any)

func Println

func Println(v ...any)

func RecordFrame

func RecordFrame(r Record) runtime.Frame

func Warn

func Warn(msg string, args ...any)

func WarnCtx

func WarnCtx(ctx context.Context, msg string, args ...any)

Types

type Action

type Action int8
const (
	ActionNone Action = iota
	ActionPanic
	ActionFatal
)

func (Action) String

func (a Action) String() string

type Attr

type Attr = slog.Attr

func Any

func Any(key string, value any) Attr

func ArgsToAttr

func ArgsToAttr(args []any) (Attr, []any)

func Bool

func Bool(key string, v bool) Attr

func Duration

func Duration(key string, v time.Duration) Attr

func E

func E(e error) Attr

func Float64

func Float64(key string, v float64) Attr

func Group

func Group(key string, as ...Attr) Attr

func Int

func Int(key string, value int) Attr

func Int64

func Int64(key string, value int64) Attr

func P

func P(v any) Attr

func String

func String(key, value string) Attr

func Time

func Time(key string, v time.Time) Attr

func Uint64

func Uint64(key string, v uint64) Attr

type Formatter

type Formatter interface {
	WithAttrs(as []Attr) Formatter
	WithGroup(name string) Formatter

	Format(r Record, w Writer) error
}

type FormatterHandler

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

func NewFormatterHandler

func NewFormatterHandler(
	f Formatter,
	w Writer,
	lv Level,
) FormatterHandler

func (*FormatterHandler) Enabled

func (h *FormatterHandler) Enabled(ctx context.Context, level Level) bool

func (*FormatterHandler) Handle

func (h *FormatterHandler) Handle(ctx context.Context, record Record) error

func (*FormatterHandler) WithAttrs

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

func (*FormatterHandler) WithGroup

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

type Handler

type Handler = slog.Handler

func DefaultHandler

func DefaultHandler() Handler

type Kind

type Kind = slog.Kind

type Level

type Level = slog.Level

func ParseLevel

func ParseLevel(s string) (Level, error)

type LevelVar

type LevelVar = slog.LevelVar

type Leveler

type Leveler = slog.Leveler

type LogPanic

type LogPanic struct {
	*Record
}

func (LogPanic) Error

func (l LogPanic) Error() string

type Logger

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

func Default

func Default() Logger

func DefaultCtx

func DefaultCtx(ctx context.Context) Logger

func NewLogger

func NewLogger(h Handler) Logger

func (Logger) Context

func (l Logger) Context() context.Context

func (Logger) Debug

func (l Logger) Debug(msg string, args ...any)

func (Logger) DefaultContext

func (l Logger) DefaultContext() context.Context

func (Logger) DefaultHandler

func (l Logger) DefaultHandler() Handler

func (Logger) Enabled

func (l Logger) Enabled(level Level) bool

func (Logger) Error

func (l Logger) Error(msg string, args ...any)

func (Logger) Fatal

func (l Logger) Fatal(obj any, args ...any)

func (Logger) Handler

func (l Logger) Handler() Handler

func (Logger) IfError

func (l Logger) IfError(err error, args ...any)

func (Logger) IfFatal

func (l Logger) IfFatal(err error, args ...any)

func (Logger) IfPanic

func (l Logger) IfPanic(err error, args ...any)

func (Logger) Info

func (l Logger) Info(msg string, args ...any)

func (Logger) Log

func (l Logger) Log(level Level, msg string, args ...any)

func (Logger) LogAttrs

func (l Logger) LogAttrs(level Level, msg string, attrs ...Attr)

func (Logger) OrError

func (l Logger) OrError(fn func() error, args ...any)

func (Logger) OrFatal

func (l Logger) OrFatal(fn func() error, args ...any)

func (Logger) OrPanic

func (l Logger) OrPanic(fn func() error, args ...any)

func (Logger) Panic

func (l Logger) Panic(obj any, args ...any)

func (Logger) Warn

func (l Logger) Warn(msg string, args ...any)

func (Logger) With

func (l Logger) With(args ...any) Logger

func (Logger) WithContext

func (l Logger) WithContext(ctx context.Context) Logger

func (Logger) WithGroup

func (l Logger) WithGroup(name string) Logger

type MultiHandler

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

func NewMultiHandler

func NewMultiHandler(hs ...Handler) MultiHandler

func (MultiHandler) Enabled

func (h MultiHandler) Enabled(ctx context.Context, level Level) bool

func (MultiHandler) Handle

func (h MultiHandler) Handle(ctx context.Context, record Record) error

func (MultiHandler) WithAttrs

func (h MultiHandler) WithAttrs(attrs []Attr) Handler

func (MultiHandler) WithGroup

func (h MultiHandler) WithGroup(name string) Handler

type NullHandler

type NullHandler struct{}

func (NullHandler) Enabled

func (h NullHandler) Enabled(ctx context.Context, level Level) bool

func (NullHandler) Handle

func (h NullHandler) Handle(ctx context.Context, record Record) error

func (NullHandler) WithAttrs

func (h NullHandler) WithAttrs(attrs []Attr) Handler

func (NullHandler) WithGroup

func (h NullHandler) WithGroup(name string) Handler

type Record

type Record = slog.Record

func NewRecord

func NewRecord(t time.Time, level Level, msg string, pc uintptr) Record

type Value

type Value = slog.Value

type Writer

type Writer = func(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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