pub struct Logger<'a, S: Db> { /* private fields */ }Expand description
Logger instance that is created over a key-value storage for a given contract-id
The logger is essentially a ring-buffer with a fixed size, that uses a specific key-space.
Implementations§
Source§impl<'a, S: Db> Logger<'a, S>
impl<'a, S: Db> Logger<'a, S>
pub fn new(db: &'a S, id: impl Into<Id>) -> Self
Sourcepub fn flush_lines(
&self,
lines: &[LogLine],
db_ptr: &S::Handle,
txn: &mut <S as Db>::RwTx<'_>,
) -> Result<()>
pub fn flush_lines( &self, lines: &[LogLine], db_ptr: &S::Handle, txn: &mut <S as Db>::RwTx<'_>, ) -> Result<()>
Flushes the given log lines into the ring-buffer.
This function writes a batch of log lines into the underlying key-value storage. It performs the following steps:
- Reads the current buffer metadata, which includes the logical start and end indices of the stored log lines.
- Determines if adding the new log lines would exceed the fixed capacity (
MAX_LOG_BUFFER_SIZE). If so, it advances the start index to overwrite the oldest entries. - Records the flush metadata (
last_flush_startandlast_flush_count) to track the range of log lines added in this flush. - Writes the new log lines to storage using modulo arithmetic to map the logical indices to physical storage keys.
- Updates and persists the modified metadata.
§Arguments
lines- A slice ofLogLineobjects to be flushed into the buffer.
§Returns
Ok(())if the flush is successful.
§Errors
Returns an error if any database operation fails or if serialization/deserialization of log lines or metadata fails.
Sourcepub fn get_full_log(&self) -> Result<Vec<LogLine>>
pub fn get_full_log(&self) -> Result<Vec<LogLine>>
Retrieves the full log from the buffer in chronological order.
Sourcepub fn get_log_lines(
&self,
start_offset: u64,
count: u64,
) -> Result<Vec<LogLine>>
pub fn get_log_lines( &self, start_offset: u64, count: u64, ) -> Result<Vec<LogLine>>
Retrieves a range of log lines from the buffer in chronological order.
§Arguments
start_offset- The number of log lines to skip from the oldest entry.count- The maximum number of log lines to retrieve.
For example, to get the 100 oldest log lines, call with start_offset = 0 and count = 100.
Sourcepub fn get_last_log(&self) -> Result<Vec<LogLine>>
pub fn get_last_log(&self) -> Result<Vec<LogLine>>
Retrieves the log lines that were flushed in the last call to flush_lines.
Sourcepub fn total_log_lines(&self) -> Result<u64>
pub fn total_log_lines(&self) -> Result<u64>
Returns the total number of log lines ever flushed.
Note that this number is the absolute index of the last flushed log line, so if logs have been overwritten in the ring-buffer, the current log count (meta.end - meta.start) may be lower.
Sourcepub fn get_logs_paginated(
&self,
pagination: Pagination,
) -> Result<PaginatedElements<LogLine>>
pub fn get_logs_paginated( &self, pagination: Pagination, ) -> Result<PaginatedElements<LogLine>>
Retrieves log lines for the given page and the total number of pages.
Auto Trait Implementations§
impl<'a, S> Freeze for Logger<'a, S>
impl<'a, S> RefUnwindSafe for Logger<'a, S>where
S: RefUnwindSafe,
impl<'a, S> Send for Logger<'a, S>
impl<'a, S> Sync for Logger<'a, S>
impl<'a, S> Unpin for Logger<'a, S>
impl<'a, S> UnwindSafe for Logger<'a, S>where
S: RefUnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more