pub struct IoWrite<W, F>{ /* private fields */ }Expand description
A thread-safe Service for byte-stream logging destinations.
IoWrite is the primary workhorse for file-based, socket-based, or
console-based logging. It implements the Service trait by wrapping its
internal data in a Mutex.
§Performance Note
This service does not explicitly call flush() after every write. If low-latency
is required with guaranteed persistence, wrap your writer in std::io::BufWriter.
Implementations§
Source§impl<W, F> IoWrite<W, F>
impl<W, F> IoWrite<W, F>
Sourcepub fn new(writer: W) -> Box<Self>
pub fn new(writer: W) -> Box<Self>
Creates a new IoWrite on the heap.
§Parameters
writer: A type implementingstd::io::Write.formatter: TheMessageFormatterimplementation.
Sourcepub fn with_formatter(writer: W, formatter: F) -> Box<Self>
pub fn with_formatter(writer: W, formatter: F) -> Box<Self>
Creates a new IoWrite on the heap with a custom formatter.
§Parameters
writer: A type implementingstd::io::Write.formatter: TheMessageFormatterimplementation.
Trait Implementations§
Source§impl<W, F> Fallback for IoWrite<W, F>
impl<W, F> Fallback for IoWrite<W, F>
Source§fn fallback(&self, error: &ServiceError, msg: &Message)
fn fallback(&self, error: &ServiceError, msg: &Message)
Best-effort fallback. Skips writing if the mutex is locked or poisoned to prevent cascading failures in the logging pipeline.
Source§impl<W, F> Service for IoWrite<W, F>
impl<W, F> Service for IoWrite<W, F>
Source§fn work(&self, msg: &Message) -> Result<(), ServiceError>
fn work(&self, msg: &Message) -> Result<(), ServiceError>
Acquires the lock and streams the formatted message to the writer.
§Errors
ServiceError::LockPoisoned: If the internalMutexis poisoned.ServiceError: If the formatter fails or the writer encounters an I/O error.
Source§fn status(&self) -> LoggerStatus
fn status(&self) -> LoggerStatus
Returns the current operational
[LoggerStatus] of the service.Auto Trait Implementations§
impl<W, F> !Freeze for IoWrite<W, F>
impl<W, F> RefUnwindSafe for IoWrite<W, F>
impl<W, F> Send for IoWrite<W, F>
impl<W, F> Sync for IoWrite<W, F>
impl<W, F> Unpin for IoWrite<W, F>
impl<W, F> UnwindSafe for IoWrite<W, F>
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
§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 moreCreates a shared type from an unshared type.