Documentation ¶
Overview ¶
// package instrumentation provides a Handler for incrementing the master error count metric, code // location logging, and advanced error annotation. It is intended to wrap // another slog.Handler, which will handle log formatting.
Index ¶
- type Handler
- func (h *Handler) Enabled(_ context.Context, level slog.Level) bool
- func (h *Handler) GetLevel() (currentLevel slog.Level, override bool)
- func (h *Handler) Handle(ctx context.Context, r slog.Record) error
- func (h *Handler) MarshalJSON() ([]byte, error)
- func (h *Handler) Name() string
- func (h *Handler) SetLevel(newLevel slog.Level, overrideParent bool) bool
- func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *Handler) WithGroup(name string) slog.Handler
- type HandlerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func NewHandler(h slog.Handler, options HandlerOptions) *Handler
func (*Handler) Enabled ¶
Enabled tells a logger whether we have been configured to log at a given level or not. It is free to ignore this, but both slog.Logger and the srv logger type will honor this. If we have a parent set, we check in with them (and down the parent chain) to see if they allow logging at this level too. This way logging can be controlled from a root level.
func (*Handler) Handle ¶
Handle implements slog.Handler. This is where errors are instrumented and counted and where the decision to print source location is made.
func (*Handler) MarshalJSON ¶
func (*Handler) WithAttrs ¶
WithAttrs is necessary to implement slog.Handler, and, since this is a wrapper it simply calls the underlying handler's method and returns a shallow copy of itself.