connectionlog

package
v2.32.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Upsert(ctx context.Context, clog database.UpsertConnectionLogParams) error
}

Backend is a destination for connection log events. Backends that also implement io.Closer will be closed when the ConnectionLogger is closed.

func NewSlogBackend

func NewSlogBackend(logger slog.Logger) Backend

NewSlogBackend returns a Backend that logs connection events via the structured logger.

type ConnectionLogger added in v2.32.0

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

ConnectionLogger fans out each connection log event to every registered backend.

func New added in v2.32.0

func New(backends ...Backend) *ConnectionLogger

New creates a ConnectionLogger that dispatches to the given backends.

func (*ConnectionLogger) Close added in v2.32.0

func (c *ConnectionLogger) Close() error

Close closes all backends that implement io.Closer.

func (*ConnectionLogger) Upsert added in v2.32.0

type DBBatcher added in v2.32.0

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

DBBatcher batches connection log upserts and periodically flushes them to the database to reduce per-event write pressure.

func NewDBBatcher added in v2.32.0

func NewDBBatcher(ctx context.Context, store database.Store, log slog.Logger, opts ...DBBatcherOption) *DBBatcher

NewDBBatcher creates a DBBatcher that batches writes to the database and starts its background processing loop. Close must be called to flush remaining entries on shutdown.

func (*DBBatcher) Close added in v2.32.0

func (b *DBBatcher) Close() error

Close cancels the batcher context, waits for the run loop and retry worker to exit.

func (*DBBatcher) Upsert added in v2.32.0

Upsert enqueues a connection log entry for batched writing. It blocks if the internal buffer is full, ensuring no logs are dropped. It returns an error if the batcher or caller context is canceled.

type DBBatcherOption added in v2.32.0

type DBBatcherOption func(b *DBBatcher)

DBBatcherOption is a functional option for configuring a DBBatcher.

func WithBatchSize added in v2.32.0

func WithBatchSize(size int) DBBatcherOption

WithBatchSize sets the maximum number of entries to accumulate before forcing a flush.

func WithClock added in v2.32.0

func WithClock(clock quartz.Clock) DBBatcherOption

WithClock sets the clock, useful for testing.

func WithFlushInterval added in v2.32.0

func WithFlushInterval(d time.Duration) DBBatcherOption

WithFlushInterval sets how frequently the batcher flushes to the database.

Jump to

Keyboard shortcuts

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