clog

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorAttributeKey = "error.message"
	StackAttributeKey = "error.stack"
)

Variables

This section is empty.

Functions

func AddAttribute

func AddAttribute(ctx context.Context, key string, value any)

func AddAttributes

func AddAttributes(ctx context.Context, attributes map[string]any)

func AddError

func AddError(ctx context.Context, err error)

func AddStack

func AddStack(ctx context.Context, stack string)

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger *slog.Logger) context.Context

ContextWithLogger returns a new context carrying the given *slog.Logger.

func ContextWithSlog

func ContextWithSlog(ctx context.Context) context.Context

func DefaultConnectHealthCheckUnaryFilter

func DefaultConnectHealthCheckUnaryFilter(spec connect.Spec) bool

func GetAttribute

func GetAttribute[T any](ctx context.Context, key string) T

func GetAttributes

func GetAttributes(ctx context.Context) map[string]any

func GetError

func GetError(ctx context.Context) error

func GetStack

func GetStack(ctx context.Context) string

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *slog.Logger

LoggerFromContext retrieves the *slog.Logger from context. If none is set, returns slog.Default().

func NewSlogConnectInterceptor

func NewSlogConnectInterceptor(opts ...ConnectOption) connect.Interceptor

func NewSlogConnectUnaryInterceptor

func NewSlogConnectUnaryInterceptor(opts ...ConnectOption) connect.UnaryInterceptorFunc

func SlogChiMiddleware

func SlogChiMiddleware(opts ...ChiOption) func(http.Handler) http.Handler

Types

type AttributesHandler

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

func NewAttributesHandler

func NewAttributesHandler(handler slog.Handler) *AttributesHandler

func (*AttributesHandler) Enabled

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

func (*AttributesHandler) Handle

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

func (*AttributesHandler) WithAttrs

func (h *AttributesHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*AttributesHandler) WithGroup

func (h *AttributesHandler) WithGroup(name string) slog.Handler

type ChiOption

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

func WithChiFilter

func WithChiFilter(filter func(r *http.Request) bool) ChiOption

type ConnectOption

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

func WithConnectFilter

func WithConnectFilter(filter func(connect.Spec) bool) ConnectOption

type ConnectTextHandler

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

func NewConnectTextHandler

func NewConnectTextHandler(w io.Writer, opts ...TextHandlerOption) *ConnectTextHandler

func (*ConnectTextHandler) Enabled

func (h *ConnectTextHandler) Enabled(ctx context.Context, l slog.Level) bool

func (*ConnectTextHandler) Handle

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

func (*ConnectTextHandler) WithAttrs

func (h *ConnectTextHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ConnectTextHandler) WithGroup

func (h *ConnectTextHandler) WithGroup(name string) slog.Handler

type HTTPTextHandler

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

func NewHTTPTextHandler

func NewHTTPTextHandler(w io.Writer, opts ...TextHandlerOption) *HTTPTextHandler

func (*HTTPTextHandler) Enabled

func (h *HTTPTextHandler) Enabled(ctx context.Context, l slog.Level) bool

func (*HTTPTextHandler) Handle

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

func (*HTTPTextHandler) WithAttrs

func (h *HTTPTextHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*HTTPTextHandler) WithGroup

func (h *HTTPTextHandler) WithGroup(name string) slog.Handler

type Level

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

func ConnectCodeToLevel

func ConnectCodeToLevel(code connect.Code) Level

func HTTPStatusToLevel

func HTTPStatusToLevel(status int) Level

type TextHandlerConfig

type TextHandlerConfig struct {
	Color bool
	Level *slog.Level
}

type TextHandlerOption

type TextHandlerOption func(*TextHandlerConfig)

func WithColor

func WithColor(c bool) TextHandlerOption

func WithLevel

func WithLevel(level slog.Level) TextHandlerOption

Jump to

Keyboard shortcuts

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