pub struct Session { /* private fields */ }Expand description
A session is a temporary logger that will print immediately but only write when dropped. All the logs during the session will be grouped together and write once. It’s useful when you want to log a series of messages such as one session of a request. The session is panic-safe, which means it will write all the logs when panic.
Apart from the formatter, the session can be Silent. If it’s silent, then the header & footer
will not be printed or written if the session never logged anything. 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, then it acts like a normal session.
Implementations§
Source§impl Session
impl Session
Sourcepub fn session(&self, name: impl Into<String>, silent: bool) -> Self
pub fn session(&self, name: impl Into<String>, silent: bool) -> Self
Create a new session from the session.
This is useful when you want to create a sub-session from a session. The sub-session will later be nested under the parent session when written.
Sourcepub fn session_then<F, T>(
&self,
name: impl Into<String>,
silent: bool,
callable: F,
) -> Twhere
F: FnOnce(Self) -> T,
pub fn session_then<F, T>(
&self,
name: impl Into<String>,
silent: bool,
callable: F,
) -> Twhere
F: FnOnce(Self) -> 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.