groupfilterhandler

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

README

groupfilterhandler

This is a slog.Handler implementation that allows filtering all but selected groups from the log output.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GroupFilterHandler

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

GroupFilterHandler is a slog.Handler that filters log records based on the group associated with it. It only forwards log records to the underlying handler if the group of the log record is in the allow list.

Note this only handles groups created with the WithGroup() method. It does not handle groups created with slog.Group().

func New

func New(handler slog.Handler, allowGroups ...string) *GroupFilterHandler

New creates a new GroupFilterHandler that forwards log records to the provided handler if any groups associated with it is in the allow list. In case there are no allow groups, then all log records are forwarded.

func (*GroupFilterHandler) Enabled

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

Enabled implements slog.Handler.

func (*GroupFilterHandler) Handle

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

Handle implements slog.Handler.

func (*GroupFilterHandler) WithAttrs

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

WithAttrs implements slog.Handler.

func (*GroupFilterHandler) WithGroup

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

WithGroup implements slog.Handler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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