pub struct Global(/* private fields */);Expand description
The Global logger will share the same logger instance across the entire program that has the same
name. This is useful when the logger is configured once and used in multiple places. The logger
will be created with default configurations if it does not exist.
Implementations§
Source§impl Global
impl Global
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Get a logger with the given name. If the logger does not exist, a new logger will be created and registered with the given name & default configurations.
Sourcepub fn register<F: Formatter>(name: impl Into<String>, config: Config) -> Self
pub fn register<F: Formatter>(name: impl Into<String>, config: Config) -> Self
Register a logger with the given name.
Sourcepub fn unregister(name: impl AsRef<str>)
pub fn unregister(name: impl AsRef<str>)
Unregister a logger with the given name. Logger will be dropped if no other reference exists.
Sourcepub fn session(
name: impl Into<String>,
session: impl Into<String>,
silent: bool,
) -> Session
pub fn session( name: impl Into<String>, session: impl Into<String>, silent: bool, ) -> Session
Create a session from the global logger without constructing a new logger first.
Sourcepub fn session_then<F, T>(
&self,
name: impl Into<String>,
silent: bool,
callable: F,
) -> T
pub fn session_then<F, T>( &self, name: impl Into<String>, silent: bool, callable: F, ) -> T
Create a new session from the session and execute the callable with the session passed in.
This can be handy for isolating the environment of each callable while also providing a common logging interface for any callable that needs to be logged.
Methods from Deref<Target = Logger>§
Sourcepub fn session(&self, name: impl Into<String>, silent: bool) -> Session
pub fn session(&self, name: impl Into<String>, silent: bool) -> Session
Create a new session from the logger.
There are two types of session: silent & non-silent. Silent session will not print the header and footer of the session when no message is logged before the session is dropped. It’s useful session that may potentially not log anything. Non-silent session will always print the header and footer of the session.
Due to the uncertainty of if the session will log anything, the header will be deferred until the first log. If the session logged anything, it’ll act like a non-silent session.
Sourcepub fn session_then<F, T>(
&self,
name: impl Into<String>,
silent: bool,
callable: F,
) -> T
pub fn session_then<F, T>( &self, name: impl Into<String>, silent: bool, callable: F, ) -> T
Create a new session from the session and execute the callable with the session passed in.
This can be handy for isolating the environment of each callable while also providing a common logging interface for any callable that needs to be logged.