Documentation
¶
Overview ¶
Package logring captures slog output into an in-memory ring buffer so a developer agent can fetch the records behind a single failed request by its request id ("one artifact per failure").
The handler wraps the logger's regular format handler (see logx.Options.WrapHandler): every record that reaches stdout is also captured here, indexed per request id (read from the request context, see webx.RequestIDFromCtx) with an LRU bound on distinct requests, plus a global tail window. String values are scrubbed through redactx by default so credentials never land in the buffer.
This is a development-observability surface, not a production log sink: it is process-local, bounded, and loses everything on restart. Products that need durable logs should ship stdout to a real aggregator (the JSON format plus request_id correlation keeps that door open).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attr ¶
Attr is one flattened key/value pair of a captured record. Group nesting is flattened to dotted keys, and values are stored as their string representation (post-redaction) so entries stay safely JSON-serializable.
type Entry ¶
type Entry struct {
Time time.Time `json:"time"`
Level slog.Level `json:"level"`
Message string `json:"message"`
RequestID string `json:"request_id,omitempty"`
Attrs []Attr `json:"attrs,omitempty"`
}
Entry is one captured log record.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the capture slog.Handler. Query the backing store via Ring.
type Options ¶
type Options struct {
// Capacity is the global tail-window size in records.
Capacity int
// PerRequestCapacity bounds the records retained per request id.
PerRequestCapacity int
// MaxRequests bounds how many distinct request ids are retained;
// the least recently used request id is evicted first.
MaxRequests int
// Redact controls scrubbing captured strings through redactx.
// Default (nil) is true.
Redact *bool
}
Options configures a Ring. Zero values fall back to the defaults above.
type Query ¶
type Query struct {
// MinLevel drops entries below this level (default: keep everything).
MinLevel slog.Level
// Limit caps the result; the newest entries win. 0 means a small
// default (100).
Limit int
}
Query filters and bounds a logring read.
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
Ring is the queryable store behind a capture Handler. Create one with New.
func (*Ring) ByRequestID ¶
ByRequestID returns the captured entries for one request, oldest first.
type Stats ¶
type Stats struct {
Captured uint64 `json:"captured"`
DroppedGlobal uint64 `json:"dropped_global"`
DroppedPerRequest uint64 `json:"dropped_per_request"`
DroppedRequests uint64 `json:"dropped_requests"`
Requests int `json:"requests"`
}
Stats is a point-in-time view of the ring for diagnostics.