svarogclient

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultDropQueueCapacity is shared by the Go logging adapter and server.
	DefaultDropQueueCapacity = 1024
	// MaxDropQueueCapacity also bounds the channel allocation when entries are small.
	MaxDropQueueCapacity = 65_536
)

Variables

View Source
var (
	ErrClosed       = errors.New("Svarog client is closed")
	ErrInvalidEntry = errors.New("invalid log entry")
	ErrQueueFull    = errors.New("Svarog log queue is full")
)

Functions

func NewHandler added in v0.0.7

func NewHandler(client *Client, options HandlerOptions) slog.Handler

NewHandler creates a handler without changing the global logger. The caller owns the client and must call its Shutdown method.

Types

type Client

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

func New

func New(options Options) (*Client, error)

New validates local configuration and starts a background publisher. It does not wait for the broker: unavailable connections retry while the queue fills.

func (*Client) Enqueue

func (c *Client) Enqueue(entry Entry) error

Enqueue waits for space in the bounded queue unless DropQueueCapacity is set. Success means local acceptance, not broker or database persistence. Shutdown unblocks waiting callers. Rejections are also reported locally because slog discards handler errors. Rejections are counted and diagnostics are rate limited in both modes.

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) error

Shutdown stops admission and waits for broker acknowledgements for accepted entries. Expiry cancels network operations and joins the publisher before returning an error. It does not wait for PostgreSQL and cannot recover entries left in memory after a timeout or process exit. Concurrent calls are safe; any caller's expired context aborts the shared drain.

type Entry

type Entry struct {
	// Message must not contain NUL. Each invalid UTF-8 byte becomes U+FFFD.
	Message string
	// A zero timestamp is set to time.Now once the entry obtains admission,
	// which can be later than the Enqueue call while producers wait.
	Timestamp time.Time
}

type HandlerOptions added in v0.0.7

type HandlerOptions struct {
	// Level is the minimum level sent to the client; nil means INFO.
	Level slog.Leveler
	// Console optionally receives logs too. Nil disables local console output.
	// Use an explicit handler, not the initial slog.Default().Handler().
	Console slog.Handler
}

type Options

type Options struct {
	ConnectionString string
	// InstanceID defaults to SVAROG_INSTANCE_ID, then the hostname.
	InstanceID string
	// Diagnostics defaults to stderr. It must not feed back into this client.
	Diagnostics io.Writer
	// DropQueueCapacity enables best-effort delivery with this many queue slots
	// and a fixed 16 MiB encoded payload budget. Zero uses the blocking 16-slot queue.
	DropQueueCapacity int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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