logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package logger provides a structured slog-based logger.

Log entries are sent to two destinations:

  • BrowserHandler: serialises records to JSON and pushes them into a channel consumed by the realtime module (centrifuge → browser console).
  • os.Stderr: only for Fatal/Error level so the operator sees critical issues without opening a browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BrowserHandler

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

BrowserHandler implements slog.Handler and pushes JSON-encoded LogEntry values into a buffered channel for consumption by the realtime module.

func New

New builds a *slog.Logger and the associated BrowserHandler.

The logger fans out to:

  • BrowserHandler (all levels >= cfg.Level) → centrifuge channel
  • slog.TextHandler on stderr (Error+ only) → terminal for fatal cases

func (*BrowserHandler) Chan

func (h *BrowserHandler) Chan() <-chan []byte

Chan returns the read-only channel of JSON-encoded log entries. The realtime module drains this channel and publishes to centrifuge.

func (*BrowserHandler) Enabled

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

func (*BrowserHandler) Handle

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

func (*BrowserHandler) WithAttrs

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

func (*BrowserHandler) WithGroup

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

type LogEntry

type LogEntry struct {
	Level string         `json:"level"`
	Msg   string         `json:"msg"`
	Time  time.Time      `json:"time"`
	Attrs map[string]any `json:"attrs,omitempty"`
}

LogEntry is the JSON payload sent to the browser via centrifuge.

Jump to

Keyboard shortcuts

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