pub struct AccessLogHook { /* private fields */ }Expand description
A DispatchHook that writes one JSON line per call to an arbitrary
Write sink. Entries carry the vgi_rpc.access logger name so the
Python validator’s filter (.logger == "vgi_rpc.access") matches.
Two modes:
AccessLogHook::new/ [to_stderr] write synchronously on the dispatch thread (acceptable for stderr or in-memory test sinks).AccessLogHook::bufferedqueues into a bounded mpsc channel and drains on a background thread; on overflow it drops the entry and bumps a counter rather than blocking dispatch.
Implementations§
Source§impl AccessLogHook
impl AccessLogHook
Sourcepub fn new<W: Write + Send + 'static>(
sink: W,
server_version: impl Into<String>,
) -> Arc<Self> ⓘ
pub fn new<W: Write + Send + 'static>( sink: W, server_version: impl Into<String>, ) -> Arc<Self> ⓘ
Create an access log hook that writes synchronously to sink.
Suitable for stderr or in-memory sinks; for production file I/O
prefer AccessLogHook::buffered to keep dispatch threads off
the disk path.
Sourcepub fn with_verbose(self: Arc<Self>, verbose: bool) -> Arc<Self> ⓘ
pub fn with_verbose(self: Arc<Self>, verbose: bool) -> Arc<Self> ⓘ
Return a new Arc<AccessLogHook> with verbose request-data
emission enabled. Mirrors Python’s
_access_logger.isEnabledFor(logging.DEBUG) behaviour where
the full base64-encoded request batch is included verbatim
rather than being elided via truncated: true.
Sourcepub fn buffered<W: Write + Send + 'static>(
sink: W,
server_version: impl Into<String>,
capacity: usize,
) -> Arc<Self> ⓘ
pub fn buffered<W: Write + Send + 'static>( sink: W, server_version: impl Into<String>, capacity: usize, ) -> Arc<Self> ⓘ
Create a hook that writes asynchronously: the dispatch thread
pushes a formatted line into a bounded channel of capacity
entries and a background thread drains it into sink. When the
channel is full, the entry is dropped (counted by
dropped_count) instead of blocking
dispatch — this is the right tradeoff for high-throughput servers
where occasional log loss is preferable to head-of-line blocking
behind a stalled disk.
The writer thread exits when the hook is dropped (sender closes).
Sourcepub fn to_stderr(server_version: impl Into<String>) -> Arc<Self> ⓘ
pub fn to_stderr(server_version: impl Into<String>) -> Arc<Self> ⓘ
Convenience: write access logs to stderr synchronously (one JSON line per entry).
Sourcepub fn dropped_count(&self) -> u64
pub fn dropped_count(&self) -> u64
Number of entries dropped because the async channel was full. Always zero for synchronous hooks.
Trait Implementations§
Source§impl DispatchHook for AccessLogHook
impl DispatchHook for AccessLogHook
Source§fn on_dispatch_start(&self, _info: &DispatchInfo) -> HookToken
fn on_dispatch_start(&self, _info: &DispatchInfo) -> HookToken
on_dispatch_end.