log_reroute

Struct Reroute

Source
pub struct Reroute { /* private fields */ }
Expand description

A logging proxy.

This logger forwards all calls to currently configured slave logger.

The log routing is implemented in a lock-less and wait-less manner. While not necessarily faster than using a mutex, the performance should be more predictable and stable in face of contention from multiple threads. This assumes the slave logger also doesn’t lock.

Implementations§

Source§

impl Reroute

Source

pub fn new() -> Self

Creates a new Reroute logger.

No destination is set yet (it’s sent to the Dummy instance), therefore all log messages are thrown away.

Source

pub fn reroute_boxed(&self, log: Box<dyn Log>)

Sets a new slave logger.

In case it is already in a box, you should prefer this method over reroute, since there’ll be less indirection.

The old logger (if any) is flushed before dropping. In general, loggers should flush themselves on drop, but that may take time. This way we (mostly) ensure the cost of flushing is paid here.

Source

pub fn reroute_arc(&self, log: Arc<Box<dyn Log>>)

Sets a slave logger.

Another variant of reroute_boxed, accepting the inner representation. This can be combined with a previous get.

Note that the Arc<Box<dyn Log>> (double indirection) is necessary evil, since arc-swap can’t accept !Sized types.

Source

pub fn reroute<L: Log + 'static>(&self, log: L)

Sets a new slave logger.

See reroute_boxed for more details.

Source

pub fn clear(&self)

Stubs out the logger.

Sets the slave logger to one that does nothing (eg. Dummy).

Source

pub fn get(&self) -> Arc<Box<dyn Log>>

Gives access to the inner logger.

§Notes

The logger may be still in use by other threads, etc. It may be in use even after the current thread called clear or reroute, at least for a while.

Trait Implementations§

Source§

impl Default for Reroute

Source§

fn default() -> Self

Creates a reroute with a Dummy slave logger.

Source§

impl Log for Reroute

Source§

fn enabled(&self, metadata: &Metadata<'_>) -> bool

Determines if a log message with the specified metadata would be logged. Read more
Source§

fn log(&self, record: &Record<'_>)

Logs the Record. Read more
Source§

fn flush(&self)

Flushes any buffered records. 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>,

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.