slogbuf

package
v0.48.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package slogbuf implements a Buffer that stores log records that can later be replayed on a slog.Handler. This is particularly useful for bootstrap.

Example: let's say log configuration is stored in an external config source, but the config load mechanism itself wants a logger. A slogbuf "boot logger" can be passed to the config load mechanism. On successful boot, the "real" logger can be created, and slogbuf's records can be replayed on that logger. If boot fails, slogbuf's records can be replayed to stderr.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer stores slog records that can be replayed via Buffer.Flush.

func New

func New() (*slog.Logger, *Buffer)

New returns a logger, and a buffer that can be used for replay.

func (*Buffer) Flush

func (b *Buffer) Flush(ctx context.Context, dest slog.Handler) error

Flush replays the buffer on dest. If an error occurs writing the log records to dest, Flush returns immediately (and does not write any remaining records). The buffer drains, even if an error occurs.

Jump to

Keyboard shortcuts

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