slug

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 11 Imported by: 1

README

Slug

Go Reference GitHub

Slug is a slog.Handler that writes human-readable logs.

⚠ Slug is still in early development and can be a bit unstable.

Features

  • Colours!

  • Non-printable characters are escaped

Non-Features

  • Performance

    Being fast or low on resources is not a goal

  • Predictable syntax

    The output is meant for human eyes only, not to be parsed

Documentation

Index

Constants

View Source
const (
	// DefaultTimeFormat is the default format for any [time.Time] logged.
	DefaultTimeFormat = "2006-01-02T15:04:05,000Z07:00"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler is a slog.Handler that writes human-readable logs.

func NewHandler

func NewHandler(options HandlerOptions, w io.Writer) *Handler

NewHandler returns a new Handler with HandlerOptions.

func (*Handler) Enabled

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

Enabled returns true if a message at a slog.Level would be logged.

func (*Handler) Handle

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

Handle handles a slog.Record.

func (*Handler) Level

func (h *Handler) Level() slog.Level

Level returns the current slog.Level.

func (*Handler) WithAttrs

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

WithAttrs returns a hew Handler with additional attributes.

func (*Handler) WithGroup

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

WithGroup returns a hew Handler with an additional group.

type HandlerOptions

type HandlerOptions struct {
	// Use all of [slog.HandlerOptions].
	slog.HandlerOptions

	// Language for formatting numbers.
	Language language.Tag

	// TimeFormat for timestamps and [time.Time] attributes. Defaults to
	// [DefaultTimeFormat] if unset.
	TimeFormat string
}

HandlerOptions are options for a Handler.

Directories

Path Synopsis
_doc
img

Jump to

Keyboard shortcuts

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