pub struct LogManager { /* private fields */ }Expand description
LogManager acts as a registry and dispatcher for multiple logging channels.
It maintains a default_logger for general use and a HashMap of specialized
channels, using a high-performance FNV hasher for fast lookups.
§Key Features
- Default Channel: The default channels is always set. By default, an implementation of
crate::SilentLogger. - Channel Routing: Dispatch logs to specific destinations via string identifiers.
- Fluent Interface: Methods like
log()return&Selfto allow for chaining. - FVN-1 Hash: Uses FVN-1 hash to store the logs. Be careful about collisions!
Implementations§
Source§impl LogManager
impl LogManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new LogManager with a SilentLogger implementation as the default.
Logs sent to a new manager will be discarded until a default is set.
Sourcepub fn new_default(default_logger: Logger) -> Self
pub fn new_default(default_logger: Logger) -> Self
Creates a manager with a pre-configured default Logger.
Sourcepub fn get_logger<Q>(&self, channel: &Q) -> Option<Logger>
pub fn get_logger<Q>(&self, channel: &Q) -> Option<Logger>
Sourcepub fn set_logger<S>(&mut self, channel: S, logger: Logger)
pub fn set_logger<S>(&mut self, channel: S, logger: Logger)
Registers or updates a Logger for a specific channel name.
Using the name "default" will overwrite the default_logger.
Sourcepub fn remove_logger<Q>(&mut self, channel: &Q) -> Option<Logger>
pub fn remove_logger<Q>(&mut self, channel: &Q) -> Option<Logger>
Sourcepub fn get_default_logger(&self) -> Logger
pub fn get_default_logger(&self) -> Logger
Returns a cloned instance of the current primary (default) Logger.
Sourcepub fn set_default_logger(&mut self, default_logger: Logger)
pub fn set_default_logger(&mut self, default_logger: Logger)
Directly updates the default Logger, bypassing the channel map.
Sourcepub fn log_channel<Q, L>(&self, channel: &Q, message: L) -> &Self
pub fn log_channel<Q, L>(&self, channel: &Q, message: L) -> &Self
Dispatches a message to a specific named channel.
Warning: If the channel does not exist, the log will be silently dropped.
Use get_logger() beforehand if you need to guarantee delivery.
§Example
let log_manager = LogManager::new();
log_manager.log_channel("default", ("INFO","System started"))
.log_channel("default", (LogLevel::Info,"Initializing..."));Auto Trait Implementations§
impl Freeze for LogManager
impl !RefUnwindSafe for LogManager
impl Send for LogManager
impl Sync for LogManager
impl Unpin for LogManager
impl !UnwindSafe for LogManager
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
§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