logging

package
v1.23.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package logging provides logging helpers.

Index

Constants

View Source
const (
	// LevelDPanic panics in debug builds.
	LevelDPanic = slog.LevelError + 1

	// LevelPanic always panics.
	LevelPanic = slog.LevelError + 2

	// LevelFatal exits with a non-zero status.
	LevelFatal = slog.LevelError + 3
)

Variables

View Source
var RecentEntries = NewCircularBuffer(1024)

RecentEntries implements log records interception and stores the last 1024 entries in circular buffer in memory.

Functions

func Error added in v1.23.0

func Error(err error) slog.Attr

Error returns slog.Attr for the given error (that can be nil) with error's message as a value.

func GoError added in v1.23.0

func GoError(err error) slog.Attr

GoError returns slog.Attr for the given error (that can be nil) with error's Go representation as a value.

func NewCircularBuffer added in v0.4.0

func NewCircularBuffer(size int) *circularBuffer

NewCircularBuffer creates a circular buffer for log records in memory.

func NewPgxLogger added in v1.23.0

func NewPgxLogger(l *slog.Logger) tracelog.Logger

NewPgxLogger creates a new tracelog.Logger that uses given slog.Logger.

func Setup

func Setup(opts *NewHandlerOpts, uuid string)

Setup initializes slog logging with given options and UUID.

func WithName added in v1.23.0

func WithName(l *slog.Logger, name string) *slog.Logger

WithName returns a logger with a given period-separated name.

How this name is used depends on the handler.

Types

type Handler added in v1.23.0

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

Handler is a slog.Handler that wraps another handler with support for additional log levels and shorter source location.

func NewHandler added in v1.23.0

func NewHandler(out io.Writer, opts *NewHandlerOpts) *Handler

NewHandler creates a new handler with the given options.

func (*Handler) Enabled added in v1.23.0

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

Enabled implements slog.Handler.

func (*Handler) Handle added in v1.23.0

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

Handle implements slog.Handler.

Also appends the record to RecentEntries used by `getLog` command.

func (*Handler) WithAttrs added in v1.23.0

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

WithAttrs implements slog.Handler.

func (*Handler) WithGroup added in v1.23.0

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

WithGroup implements slog.Handler.

type NewHandlerOpts added in v1.23.0

type NewHandlerOpts struct {
	Base         string // base handler to create: "console", "text", or "json"
	Level        slog.Leveler
	RemoveTime   bool
	RemoveLevel  bool
	RemoveSource bool
}

NewHandlerOpts represents NewHandler options.

Jump to

Keyboard shortcuts

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