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 ¶
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
func (c *ConnectionLogger) Upsert(ctx context.Context, clog database.UpsertConnectionLogParams) error
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
Close cancels the batcher context, waits for the run loop and retry worker to exit.
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.