pub struct Logger { /* private fields */ }Expand description
A thread-safe, high-level wrapper around a logging implementation.
Logger acts as the primary entry point for the application. It uses
an Arc internally to allow cheap cloning and safe sharing across
asynchronous tasks or threads.
Loggers can be easily built using LoggerFactory.
Because it uses an Arc internally, cloning a Logger is extremely cheap—
it only increments a reference count. This allows you to pass the logger
into multiple threads, closures, or asynchronous tasks easily.
Implementations§
Source§impl Logger
impl Logger
Sourcepub fn new(implementation: Box<dyn LoggerImpl + Send + Sync>) -> Logger
pub fn new(implementation: Box<dyn LoggerImpl + Send + Sync>) -> Logger
Creates a new Logger instance with the specified backend implementation.
§Example
let logger = Logger::new(SilentLogger::new());Sourcepub fn status(&self) -> LoggerStatus
pub fn status(&self) -> LoggerStatus
Returns the current LoggerStatus of the underlying logging backend.
This provides a quick check to see if the logging service is Running
or has become Broken (e.g., due to a disk failure or network disconnection).
Sourcepub fn log<T: Loggable>(&self, message: T) -> &Logger
pub fn log<T: Loggable>(&self, message: T) -> &Logger
Logs an entry that implements the Loggable trait.
This method uses static dispatch (monomorphization) to resolve the
input T into a Message before passing it to the internal implementation.
The enumeration LogLevel implements Display and can be used as levels.
§Returns
Returns a reference to self to enable Method Chaining (Fluent API).
§Example
logger.log((LogLevel::Info, "Step 1"))
.log((LogLevel::Info, "Step 2"));§Arguments
message- Anything that can be converted into a log message, typically a tuple such as(Level::Info, "Hello World").
Sourcepub fn get_implementation(&self) -> &dyn LoggerImpl
pub fn get_implementation(&self) -> &dyn LoggerImpl
Provides access to the underlying LoggerImpl.
This is useful for accessing backend-specific methods or performing downcasts via Any.
Sourcepub fn take_implementation(self) -> Arc<dyn LoggerImpl>
pub fn take_implementation(self) -> Arc<dyn LoggerImpl>
Destroys the logger and returns the underlying LoggerImpl.
Another logger may be using this implementation elsewhere.
This is useful for accessing backend-specific methods or performing downcasts via Any.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Logger
impl !RefUnwindSafe for Logger
impl Send for Logger
impl Sync for Logger
impl Unpin for Logger
impl !UnwindSafe for Logger
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> 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>
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