Skip to main content

AccessLogHook

Struct AccessLogHook 

Source
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::buffered queues 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

Source

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.

Source

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.

Source

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).

Source

pub fn to_stderr(server_version: impl Into<String>) -> Arc<Self>

Convenience: write access logs to stderr synchronously (one JSON line per entry).

Source

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

Source§

fn on_dispatch_start(&self, _info: &DispatchInfo) -> HookToken

Invoked just before the handler runs. Return a token that will be passed to on_dispatch_end.
Source§

fn on_dispatch_end( &self, token: HookToken, info: &DispatchInfo, error: Option<&RpcError>, stats: &CallStatistics, )

Invoked once the handler has returned and all logs/batches have been written to the transport.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more