Struct session_log::Global

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

source

pub fn new(name: &str) -> 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.

source

pub fn register<F: Formatter>(name: &str, config: Config) -> Self

Register a logger with the given name.

source

pub fn unregister(name: &str)

Unregister a logger with the given name. Logger will be dropped if no other reference exists.

source

pub fn session(name: &str, session: &str, silent: bool) -> Session

Create a session from the global logger without constructing a new logger first.

source

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

source

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

source

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

source§

fn clone(&self) -> Global

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Deref for Global

source§

type Target = Logger

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Global

§

impl RefUnwindSafe for Global

§

impl Send for Global

§

impl Sync for Global

§

impl Unpin for Global

§

impl UnwindSafe for Global

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.