LogGuard

Struct LogGuard 

Source
pub struct LogGuard {
    pub log_buffer: VecDeque<LogEntry>,
    pub log_level: LogLevel,
    pub log_limit: usize,
}
Expand description

Log monitoring state.

Buffers recent Tor log messages and provides functionality to dump them when circuits are closed for debugging purposes.

§Buffer Behavior

The log buffer operates as a ring buffer with a configurable maximum size. When the buffer is full, the oldest entries are discarded to make room for new ones.

§Example

use vanguards_rs::logguard::LogGuard;
use vanguards_rs::config::LogguardConfig;

let config = LogguardConfig::default();
let mut guard = LogGuard::new(&config);

// Buffer log entries
guard.log_event("NOTICE", "Circuit 123 built");
guard.log_event("INFO", "Stream attached");
assert_eq!(guard.buffer_len(), 2);

// Dump logs before circuit close
guard.dump_log_queue("123", "Pre");
assert_eq!(guard.buffer_len(), 0);

§Event Handling

The guard responds to circuit events:

  • On CLOSED or FAILED with reason REQUESTED: Dumps buffered logs
  • This captures context around intentional circuit closures

§See Also

Fields§

§log_buffer: VecDeque<LogEntry>

Buffered log entries.

§log_level: LogLevel

Minimum log level to buffer.

§log_limit: usize

Maximum number of entries to buffer.

Implementations§

Source§

impl LogGuard

Source

pub fn new(config: &LogguardConfig) -> Self

Creates a new LogGuard with the specified configuration.

Source

pub fn log_event(&mut self, runlevel: &str, message: &str)

Handles a log event from Tor.

Buffers the log entry if it meets the minimum log level requirement. Automatically trims the buffer if it exceeds the configured limit.

§Arguments
  • runlevel - The log level (DEBUG, INFO, NOTICE, WARN, ERR)
  • message - The log message content
Source

pub fn log_event_with_timestamp( &mut self, runlevel: &str, message: &str, arrived_at: f64, )

Handles a log event with a specific timestamp.

Source

pub fn log_warn_event(&self, message: &str)

Handles a WARN-level log event.

Logs the warning at NOTICE level for visibility.

Source

pub fn dump_log_queue(&mut self, circ_id: &str, when: &str)

Dumps the log buffer for a circuit close event.

This is called before and after circuit close. The “when” argument is “Pre” before we close a circuit and “Post” after.

§Arguments
  • circ_id - The circuit ID being closed
  • when - “Pre” for before close, “Post” for after close
Source

pub fn circ_event(&mut self, circ_id: &str, status: &str, reason: Option<&str>)

Handles a circuit event for post-close log dumping.

Dumps buffered logs after a circuit is closed with REQUESTED reason.

§Arguments
  • circ_id - The circuit ID
  • status - The circuit status (CLOSED, FAILED, etc.)
  • reason - The close reason
Source

pub fn buffer_len(&self) -> usize

Returns the number of buffered log entries.

Source

pub fn clear(&mut self)

Clears the log buffer.

Source

pub fn get_log_event_types(dump_level: LogLevel) -> Vec<&'static str>

Returns the log levels that should be subscribed to based on dump_level.

Returns a list of Tor event types to subscribe to.

Trait Implementations§

Source§

impl Clone for LogGuard

Source§

fn clone(&self) -> LogGuard

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LogGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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