slogpretty

package
v0.0.0-...-630cbcc Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package slogpretty provides a custom slog.Handler that formats log records with colorized levels, indented JSON fields, and timestamp prefixes for human-readable output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PrettyHandler

type PrettyHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

PrettyHandler is a slog.Handler implementation that outputs logs in a human-friendly format with ANSI color codes and indented JSON fields.

func (*PrettyHandler) Handle

func (h *PrettyHandler) Handle(_ context.Context, r slog.Record) error

Handle processes a log record by formatting it with colorized level, timestamp, message, and pretty-printed JSON attributes. Implements slog.Handler.

func (*PrettyHandler) WithAttrs

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

WithAttrs returns a new PrettyHandler with additional attributes prepended to future log records. Implements slog.Handler.

func (*PrettyHandler) WithGroup

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

WithGroup returns a new PrettyHandler that starts a group for subsequent attributes. Implements slog.Handler.

type PrettyHandlerOptions

type PrettyHandlerOptions struct {
	SlogOpts *slog.HandlerOptions
}

PrettyHandlerOptions configures the behavior of the PrettyHandler. It embeds slog.HandlerOptions to inherit standard handler configurations.

func (PrettyHandlerOptions) NewPrettyHandler

func (opts PrettyHandlerOptions) NewPrettyHandler(
	out io.Writer,
) *PrettyHandler

NewPrettyHandler creates a new PrettyHandler that writes to the given output. It combines colorized level prefixes, timestamp, message, and indented JSON attributes for improved readability.

Jump to

Keyboard shortcuts

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