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>
impl<T: Send + Sync + Default + Copy + 'static> Logger<T>
Sourcepub fn with_write_config(
self,
logpath: String,
capacity: usize,
flush_interval: u64,
poll_interval: u64,
pre_alloc_size: u64,
) -> Self
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.
Sourcepub fn start(&mut self) -> Result<(), Error>
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.
Sourcepub fn with_read_config(self, logpath: String) -> Self
pub fn with_read_config(self, logpath: String) -> Self
Sourcepub fn read(&self) -> Result<Vec<T>, Error>
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.
Sourcepub fn get_last_flushed_entry() -> u64
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§
Auto Trait Implementations§
impl<T> Freeze for Logger<T>
impl<T> !RefUnwindSafe for Logger<T>
impl<T> Send for Logger<T>
impl<T> Sync for Logger<T>
impl<T> Unpin for Logger<T>
impl<T> !UnwindSafe for Logger<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more