Struct session_log::Session

source ·
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

source

pub fn session(&self, name: &str, 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.

source

pub fn session_then<F, T>(&self, name: &str, silent: bool, callable: F) -> T
where 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.

Trait Implementations§

source§

impl Drop for Session

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Loggable for Session

source§

fn root_name(&self) -> &str

Get the name of the root logger.
source§

fn name(&self) -> &str

Get the name of current logger.
source§

fn path(&self) -> String

Get the path of the log file.
source§

fn write_level(&self) -> Level

Get the writing level of the root logger.
source§

fn print_level(&self) -> Level

Get the printing level of the root logger.
source§

fn debug(&self, message: &str)

Log a message with debug level.
source§

fn verbose(&self, message: &str)

Log a message with verbose level.
source§

fn info(&self, message: &str)

Log a message with info level.
source§

fn warning(&self, message: &str)

Log a message with warning level.
source§

fn critical(&self, message: &str)

Log a message with critical level.
source§

fn error(&self, message: &str)

Log a message with error level.
source§

fn fatal(&self, message: &str) -> !

Log a message with fatal level. The program will panic after logging the message.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.