Skip to main content

RingBufferLogger

Struct RingBufferLogger 

Source
pub struct RingBufferLogger { /* private fields */ }
Expand description

Ring buffer logger with bounded memory usage.

Uses RwLock for concurrent read scalability - multiple threads can call get_recent() simultaneously without contention.

Implementations§

Source§

impl RingBufferLogger

Source

pub fn new(max_entries: usize, max_entry_bytes: usize) -> Self

Create a new ring buffer logger.

§Arguments
  • max_entries - Maximum number of entries before FIFO eviction
  • max_entry_bytes - Maximum bytes per entry (defensive cap)
§Example
use palisade_errors::ring_buffer::RingBufferLogger;

// Typical honeypot: 10k entries, 1KB each = 10MB max
let logger = RingBufferLogger::new(10_000, 1024);
Source

pub fn log(&self, err: &AgentError, source_ip: &str)

Log an error with automatic eviction if buffer is full.

§Arguments
  • err - The error to log
  • source_ip - Source IP or identifier for tracking
§Example
let logger = RingBufferLogger::new(100, 1024);
let err = AgentError::config(definitions::CFG_PARSE_FAILED, "op", "details");
logger.log(&err, "192.168.1.100");
Source

pub fn get_recent(&self, count: usize) -> Vec<ForensicEntry>

Get the N most recent entries in reverse chronological order.

Uses read lock for concurrent access - multiple threads can call this simultaneously without blocking each other.

§Example
// Get last 10 errors
let recent = logger.get_recent(10);
for entry in recent {
    println!("[{}] {} - {}", entry.timestamp, entry.code, entry.operation);
}
Source

pub fn get_all(&self) -> Vec<ForensicEntry>

Get all entries in reverse chronological order.

Source

pub fn get_filtered<F>(&self, predicate: F) -> Vec<ForensicEntry>
where F: Fn(&ForensicEntry) -> bool,

Get entries matching a predicate (e.g., filter by source IP).

§Example
// Get all errors from specific IP
let from_attacker = logger.get_filtered(|entry| {
    entry.source_ip.as_ref() == "192.168.1.100"
});
Source

pub fn len(&self) -> usize

Get current number of entries in buffer.

Source

pub fn is_empty(&self) -> bool

Check if buffer is empty.

Source

pub fn payload_bytes(&self) -> usize

Get total payload bytes (lower-bound estimate).

Source

pub fn eviction_count(&self) -> u64

Get total number of evictions since creation.

High eviction rate indicates sustained attack volume.

Source

pub fn clear(&self)

Clear all entries (useful after archival or testing).

Source

pub fn capacity(&self) -> usize

Get buffer capacity.

Source

pub fn is_full(&self) -> bool

Check if buffer is at capacity.

Trait Implementations§

Source§

impl Clone for RingBufferLogger

Source§

fn clone(&self) -> Self

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

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.

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