pub struct MemoryDrainForTest { /* private fields */ }
Expand description
A testing infrastructure for logging that consists of two main components:
- MemoryDrainForTest: A slog Drain that stores records in memory
- MemoryDrainForTestInspector: A component that provides methods to analyze stored logs
Records are stored as formatted strings in a thread-safe vector using Arc<RwLock>
.
Each log record follows the format:
{LEVEL} {MESSAGE}; {KEY1}={VALUE1}, {KEY2}={VALUE2}, ...
where:
- LEVEL: The log level (DEBUG, INFO, etc.)
- MESSAGE: The main log message
- KEY=VALUE pairs: Additional context values attached to the log
§Performance Considerations
This drain implementation is designed for testing purposes and is not optimized for performance. It uses an RwLock for each log operation and string formatting, which may introduce significant overhead.
Implementations§
Source§impl MemoryDrainForTest
impl MemoryDrainForTest
Sourcepub fn new() -> (Self, MemoryDrainForTestInspector)
pub fn new() -> (Self, MemoryDrainForTestInspector)
Creates a new instance of MemoryDrainForTest
Trait Implementations§
Source§impl Clone for MemoryDrainForTest
impl Clone for MemoryDrainForTest
Source§fn clone(&self) -> MemoryDrainForTest
fn clone(&self) -> MemoryDrainForTest
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Default for MemoryDrainForTest
impl Default for MemoryDrainForTest
Source§fn default() -> MemoryDrainForTest
fn default() -> MemoryDrainForTest
Returns the “default value” for a type. Read more
Source§impl Drain for MemoryDrainForTest
impl Drain for MemoryDrainForTest
Source§fn log(
&self,
record: &Record<'_>,
values: &OwnedKVList,
) -> Result<Self::Ok, Self::Err>
fn log( &self, record: &Record<'_>, values: &OwnedKVList, ) -> Result<Self::Ok, Self::Err>
Handle one logging statement (
Record
) Read more§fn is_enabled(&self, level: Level) -> bool
fn is_enabled(&self, level: Level) -> bool
Avoid: Check if messages at the specified log level are maybe
enabled for this logger. Read more
§fn is_critical_enabled(&self) -> bool
fn is_critical_enabled(&self) -> bool
Avoid: See
is_enabled
§fn is_error_enabled(&self) -> bool
fn is_error_enabled(&self) -> bool
Avoid: See
is_enabled
§fn is_warning_enabled(&self) -> bool
fn is_warning_enabled(&self) -> bool
Avoid: See
is_enabled
§fn is_info_enabled(&self) -> bool
fn is_info_enabled(&self) -> bool
Avoid: See
is_enabled
§fn is_debug_enabled(&self) -> bool
fn is_debug_enabled(&self) -> bool
Avoid: See
is_enabled
§fn is_trace_enabled(&self) -> bool
fn is_trace_enabled(&self) -> bool
Avoid: See
is_enabled
§fn filter<F>(self, f: F) -> Filter<Self, F>where
Self: Sized,
F: FilterFn,
fn filter<F>(self, f: F) -> Filter<Self, F>where
Self: Sized,
F: FilterFn,
Filter logging records passed to
Drain
Read more§fn filter_level(self, level: Level) -> LevelFilter<Self>where
Self: Sized,
fn filter_level(self, level: Level) -> LevelFilter<Self>where
Self: Sized,
Filter logging records passed to
Drain
(by level) Read more§fn map_err<F, E>(self, f: F) -> MapError<Self, E>where
Self: Sized,
F: MapErrFn<Self::Err, E>,
fn map_err<F, E>(self, f: F) -> MapError<Self, E>where
Self: Sized,
F: MapErrFn<Self::Err, E>,
Map logging errors returned by this drain Read more
§fn ignore_res(self) -> IgnoreResult<Self>where
Self: Sized,
fn ignore_res(self) -> IgnoreResult<Self>where
Self: Sized,
Ignore results returned by this drain Read more
Auto Trait Implementations§
impl Freeze for MemoryDrainForTest
impl RefUnwindSafe for MemoryDrainForTest
impl Send for MemoryDrainForTest
impl Sync for MemoryDrainForTest
impl Unpin for MemoryDrainForTest
impl UnwindSafe for MemoryDrainForTest
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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 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>
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 moreSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.