logging

package
v2.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const AttrGroupDelimiter = ">"

Variables

This section is empty.

Functions

func GetHeaderAttrs

func GetHeaderAttrs(header http.Header, headers []string) []slog.Attr

func GroupAttrsRecursive

func GroupAttrsRecursive(attrs []slog.Attr) []slog.Attr

GroupAttrsRecursive takes a list of attributes, and for each attribute that has a key that contains the group delimiter, it will be split into a nested group, replacing all of the original attributes with the same nested group.

Example:

  • keys: ["foo>bar>baz", "foo>bar>qux", "foo>baz>qux", "abc"]
  • effective result: [{"foo": {"bar": {"baz": "value", "qux": "value"}, "baz": {"qux": "value"}}, "abc": "value"}]

Types

type LimitedBuffer

type LimitedBuffer struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

LimitedBuffer is a buffer that limits the amount of bytes writeable to it. It is designed to be used for logging purposes, so the exact bytes may be exceeded, as a truncated message will be appended after the limit is reached. It will silently drop any additional bytes once the limit is reached. If the max bytes is <= 0, no limit will be applied, and the buffer will behave normally.

func NewLimitedBuffer

func NewLimitedBuffer(maxSize int) *LimitedBuffer

NewLimitedBuffer creates a new LimitedBuffer with the given maximum size.

func (*LimitedBuffer) Reset

func (b *LimitedBuffer) Reset()

func (*LimitedBuffer) Write

func (b *LimitedBuffer) Write(p []byte) (int, error)

Write writes the given bytes to the buffer, until the limit is reached, and a truncated message is appended. From there, it will silently drop any additional bytes.

type MockHandler

type MockHandler struct {
	Attrs   []slog.Attr
	Groups  []string
	Store   bool
	Records [][]slog.Attr
}

func (*MockHandler) Enabled

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

func (*MockHandler) Handle

func (h *MockHandler) Handle(_ context.Context, or slog.Record) error

func (*MockHandler) WithAttrs

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

func (*MockHandler) WithGroup

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

Jump to

Keyboard shortcuts

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