Struct Logger

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

Source

pub fn new(db: &'a S, id: impl Into<Id>) -> Self

Source

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:

  1. Reads the current buffer metadata, which includes the logical start and end indices of the stored log lines.
  2. 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.
  3. Records the flush metadata (last_flush_start and last_flush_count) to track the range of log lines added in this flush.
  4. Writes the new log lines to storage using modulo arithmetic to map the logical indices to physical storage keys.
  5. Updates and persists the modified metadata.
§Arguments
  • lines - A slice of LogLine objects 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.

Source

pub fn get_full_log(&self) -> Result<Vec<LogLine>>

Retrieves the full log from the buffer in chronological order.

Source

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.

Source

pub fn get_last_log(&self) -> Result<Vec<LogLine>>

Retrieves the log lines that were flushed in the last call to flush_lines.

Source

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.

Source

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> 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> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,