instrumentation

package
v0.0.0-...-b028674 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 8 Imported by: 0

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

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

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

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

func (h *Handler) GetLevel() (currentLevel slog.Level, override bool)

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, r slog.Record) error

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 (h *Handler) MarshalJSON() ([]byte, error)

func (*Handler) Name

func (h *Handler) Name() string

func (*Handler) SetLevel

func (h *Handler) SetLevel(newLevel slog.Level, overrideParent bool) bool

func (*Handler) WithAttrs

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

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.

func (*Handler) WithGroup

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

WithGroup is necessary to implement [slog.Handlerl. As with WithGroup, it returns a clone.

type HandlerOptions

type HandlerOptions struct {
	Name           string
	MinLevel       slog.Level
	OverrideParent bool
	ShowLocation   bool
	TrimCode       bool
	ErrorCounter   metrics.Counter
	WarnCounter    metrics.Counter
	InfoCounter    metrics.Counter
}

TODO: allow setting log level with an atomic

Jump to

Keyboard shortcuts

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