Logger

Struct Logger 

Source
pub struct Logger<T> { /* private fields */ }
Expand description

The main logger struct responsible for handling log writing and reading operations. It uses a ring buffer and a background worker thread for asynchronous logging.

Implementations§

Source§

impl<T: Send + Sync + Default + Copy + 'static> Logger<T>

Source

pub fn new() -> Self

Creates a new instance of Logger with default (empty) configuration.

Source

pub fn with_write_config( self, logpath: String, capacity: usize, flush_interval: u64, poll_interval: u64, pre_alloc_size: u64, ) -> Self

Configures the logger for writing logs.

§Arguments
  • logpath - Path to the log file.
  • capacity - Size of the ring buffer.
  • flush_interval - Interval in nanoseconds to flush logs to disk.
  • poll_interval - Interval in nanoseconds to poll for uring completions.
  • pre_alloc_size - Size in bytes to pre-allocate for the log file.
Source

pub fn start(&mut self) -> Result<(), Error>

Initializes the internal components (buffer, worker thread) and starts the logging process.

§Returns
  • Result<(), Error> - Ok if started successfully, Err if configuration is missing.
Source

pub fn with_read_config(self, logpath: String) -> Self

Configures the logger for reading logs.

§Arguments
  • logpath - Path to the log file to read from.
Source

pub fn read(&self) -> Result<Vec<T>, Error>

Reads all log entries from the configured log file.

§Returns
  • Result<Vec<T>, Error> - A vector of log data if successful, or an error.
Source

pub fn log(&mut self, data: T) -> Option<u64>

Adds a new log entry to the buffer.

§Arguments
  • data - The log data to be written.
§Returns
  • Option<u64> - The sequence ID of the log entry if successful, or None if the logger is not started.
Source

pub fn get_last_flushed_entry() -> u64

Retrieves the sequence ID of the last log entry that was successfully flushed to disk.

§Returns
  • u64 - The sequence ID.

Trait Implementations§

Source§

impl<T> Drop for Logger<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Logger<T>

§

impl<T> !RefUnwindSafe for Logger<T>

§

impl<T> Send for Logger<T>
where T: Send + Sync,

§

impl<T> Sync for Logger<T>
where T: Send + Sync,

§

impl<T> Unpin for Logger<T>

§

impl<T> !UnwindSafe for Logger<T>

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