Struct session_log::Session

source ·
pub struct Session { /* private fields */ }
Expand description

Sessions are a way to group log messages together. They are useful for tracking the flow of a program. They can be nested, and when a session is dropped, it will dump all of its messages to the file at once. Despite the file being written to at once, the messages are still written in the traditional order on the terminal. It can also be used as a simple profiling tool, as it will track the starting time of the session and the elapsed time when it is dropped.

§Example

use session_log::{Logger, Loggable};

fn main() {
  let logger = Logger::new("main");

  foo(logger.session("foo"), 10);
  bar(logger.session("bar"), 10);
}

fn foo(logger: impl Loggable, n: usize) {
  for i in 0..n {
    logger.info(&format!("message-{}", i));
  }
}

fn bar(logger: impl Loggable, n: usize) {
  for i in 0..n {
    logger.warning(&format!("message-{}", i));
  }
}

Implementations§

source§

impl Session

source

pub fn enable(&mut self)

Re-enable the session so it can log messages again.

source

pub fn disable(&mut self)

Temporarily disable the session so it will not log messages.

source

pub fn set_ease_on_empty(self, ease: bool) -> Self

Set if the session write only elapsed when empty session dump.
Default is true.

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 log(&self, ctx: Context<'_>)

Log a message with the dynamic level.
source§

fn session(&self, name: impl Into<String>) -> Session

Create a new session with the given name.
source§

fn get_name(&self) -> &str

Get the name of the current loggable.
source§

fn get_logger_name(&self) -> &str

Get the current logging entry name.
source§

fn get_logger(&self) -> Logger

Get the logger of the current loggable.
source§

fn get_session(&self) -> Option<&str>

Get the current session name.
source§

fn get_log_level(&self) -> Level

Get the log level of current loggable.
source§

fn get_write_level(&self) -> Level

Get the write level of current loggable.
source§

fn debug(&self, message: impl Into<String>)

Log a message at the debug level with caller position.
source§

fn verbose(&self, message: impl Into<String>)

Log a message at the verbose level with caller position.
source§

fn info(&self, message: impl Into<String>)

Log a message at the info level with caller position.
source§

fn warning(&self, message: impl Into<String>)

Log a message at the warning level with caller position.
source§

fn critical(&self, message: impl Into<String>)

Log a message at the critical level with caller position.
source§

fn error(&self, message: impl Into<String>)

Log a message at the error level with caller position.
source§

fn fatal(&self, message: impl Into<String>) -> !

Log a message at the fatal level with caller position then panic. Read more

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>,

§

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>,

§

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.