Documentation
¶
Overview ¶
Package froe pushes selected logs to a Froe instance, the log-sharing service. Clients and agents fetch them back with a read key over a plain REST API; the wire contract is served at GET /v1 on any instance.
The hard rule of this package: log calls never block the caller and never panic. Entries are buffered in memory and shipped as batches, strictly in order, with capped exponential backoff on failure.
Index ¶
- type Client
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) Debug(message string, meta Meta)
- func (c *Client) Error(message string, meta Meta)
- func (c *Client) Fatal(message string, meta Meta)
- func (c *Client) Flush(ctx context.Context) error
- func (c *Client) Info(message string, meta Meta)
- func (c *Client) Log(level Level, message string, meta Meta, t time.Time)
- func (c *Client) Trace(message string, meta Meta)
- func (c *Client) Warn(message string, meta Meta)
- type Handler
- type HandlerOptions
- type Level
- type Meta
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client buffers entries and ships them to one Froe instance. It is safe for concurrent use. Close it to stop its background goroutine.
func (*Client) Close ¶
Close flushes once and stops the background sender. Later Log calls still buffer, but nothing ships them.
func (*Client) Flush ¶
Flush makes one ordered delivery pass, ignoring any backoff, and returns when the pass settles. It reports only ctx errors: a batch it could not deliver stays queued for the next interval, so a shutdown hook is never held hostage by a dead server.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog.Handler that feeds records into a Client. It is a forwarder, not a replacement for your local handler: wrap it in slog.New alongside whatever writes to stderr, or use it on its own if Froe is your only sink.
func NewHandler ¶
func NewHandler(c *Client, opts *HandlerOptions) *Handler
NewHandler forwards records to c. A nil opts takes every default.
type HandlerOptions ¶
type HandlerOptions struct {
// Level is the minimum record level forwarded. Default slog.LevelInfo.
Level slog.Leveler
// ForwardAll restores the firehose for the rare app whose whole
// stream is meant to be shared, ignoring the froe=true marker.
ForwardAll bool
}
HandlerOptions configures a Handler. The zero value is the default: forward records at slog's default level that carry froe=true.
type Level ¶
type Level string
Level is a Froe severity. The set is fixed by API.md; the server rejects a whole batch on one unknown level, so unknown levels are dropped here.
type Options ¶
type Options struct {
// Key is the write key (fw_...). Required.
Key string
// URL of the Froe instance. Default https://froe.run.
URL string
// BatchSize is the buffered entry count that triggers a send.
// Default 50.
BatchSize int
// FlushInterval sends whatever is buffered even below BatchSize.
// Default 2s.
FlushInterval time.Duration
// MaxBufferedEntries is the ceiling on entries held in memory,
// counting the unformed buffer and the batches waiting in the retry
// queue together, so a single number bounds the SDK's whole
// footprint. Past it the oldest entries go first. Default 10000.
MaxBufferedEntries int
// RequestTimeout caps how long one send may hang before it is
// aborted and treated as a failed attempt. Without it, a server that
// accepts the connection but never answers ties up the head batch,
// and because the head blocks the queue nothing else would ship.
// Default 10s.
RequestTimeout time.Duration
// HTTPClient is the transport. Default a plain http.Client; the
// per-attempt deadline comes from RequestTimeout either way.
HTTPClient *http.Client
// Warn receives the SDK's own diagnostics (dropped entries, dropped
// batches, overflow). Default writes one line to stderr. It is
// called from the logging goroutine and from the sender goroutine,
// so it must be safe for concurrent use, and it must not route back
// into this Client, which would recurse.
Warn func(msg string)
}
Options configures a Client. Only Key is required; every other field falls back to the default named in its comment.