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 session(&self, name: &str) -> Result<Session, SessionErrorKind>

Create a nested session under the current session.

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, level: Level, message: &str)

Log a message with the dynamic level.
source§

fn debug(&self, message: &str)

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

fn verbose(&self, message: &str)

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

fn info(&self, message: &str)

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

fn warning(&self, message: &str)

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

fn critical(&self, message: &str)

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

fn error(&self, message: &str)

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

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

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.