Documentation
¶
Overview ¶
Package logging provides logging helpers.
Index ¶
- Constants
- Variables
- func Error(err error) slog.Attr
- func GoError(err error) slog.Attr
- func NewCircularBuffer(size int) *circularBuffer
- func NewPgxLogger(l *slog.Logger) tracelog.Logger
- func Setup(opts *NewHandlerOpts, uuid string)
- func WithName(l *slog.Logger, name string) *slog.Logger
- type Handler
- type NewHandlerOpts
Constants ¶
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 ¶
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
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
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
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.
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 (DPanic/ERROR+1 panics in debug builds, Panic/ERROR+2 always panics, Fatal/ERROR+3 exits with a non-zero status);
- shorter source locations;
- removal of time, level, and source attributes;
- message checks for leading/trailing spaces and ending punctuation;
- collecting recent log entries for `getLog` command.
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
Enabled implements slog.Handler.
func (*Handler) Handle ¶ added in v1.23.0
Handle implements slog.Handler.
func (*Handler) WithAttrs ¶ added in v1.23.0
WithAttrs 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
// When set, causes handler to panic on messages with leading/trailing spaces or ending punctuation.
// It must not be set unconditionally because we don't control messages from third-party packages.
//
// But we can enable it in our tests and when [debugbuild.Enabled] is true.
// TODO https://github.com/FerretDB/FerretDB/issues/4511
CheckMessages bool
}
NewHandlerOpts represents NewHandler options.