pub struct LogThread { /* private fields */ }
Expand description

A type for managing threads for collecting log messages.

With LogThread::spawn() one can create a new log thread whose handle is contained in the returned LogThread struct. By calling the collect() method one can tell the log thread to shut down and return the logs collected to this point. If the LogThread object gets dropped before calling collect(), the corresponding logging thread will be stopped and all collected logs will be discarded.

If one deliberately wants to discard all logging messages, one can simply create a sender to a disconnected channel via LogThread::create_disconnected_sender().

Implementations§

source§

impl LogThread

source

pub fn spawn<F>(collector_func: F) -> LogThread
where F: FnOnce(Receiver<LogThreadMsg>) -> (Vec<LogMessage>, Vec<CweWarning>) + Send + 'static,

Create a new LogThread object with a handle to a freshly spawned logging collector thread.

The parameter is the function containing the actual log collection logic. I.e. the function should receive messages through the given receiver until the channel disconnects or until it receives a LogThreadMsg::Terminate message. After that it should return the logs collected up to that point.

See LogThread::collect_and_deduplicate for a standard collector function that can be used here.

source

pub fn create_disconnected_sender() -> Sender<LogThreadMsg>

Just create a disconnected sender to a (non-existing) logging thread. Can be used like a sender to a channel that deliberately discards all messages sent to it.

source

pub fn get_msg_sender(&self) -> Sender<LogThreadMsg>

Get a sender that can be used to send messages to the logging thread corresponding to this LogThread instance.

source

pub fn collect(self) -> (Vec<LogMessage>, Vec<CweWarning>)

Stop the logging thread by sending it the Terminate signal and then return all logs collected until that point.

source

pub fn collect_and_deduplicate( receiver: Receiver<LogThreadMsg> ) -> (Vec<LogMessage>, Vec<CweWarning>)

This function is collects logs from the given receiver until a LogThreadMsg::Terminate signal is received. All collected logs are deduplicated before being returned.

CWE warnings and log messages are deduplicated if two messages share the same address of origin. In such a case only the last message received is kept. If a CWE message has more than one address only the first address is considered when deduplicating. Note that this may lead to information loss if log messages with the same origin address that are not duplicates are generated.

This function can be used as a standard collector function for LogThread::spawn.

Trait Implementations§

source§

impl Drop for LogThread

source§

fn drop(&mut self)

If the logging thread still exists, send it the Terminate signal. Then wait until the logging thread stopped.

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.