LogObserver

Struct LogObserver 

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

A LogObserver reads Minecraft’s log file and sends LogEvents to registered listeners. It is used internally by a MinecraftConnection, but can be used explicitely as well, when executing commands is not neccessary.

Internally LogEvents are send to listeners via unbound channels. This means the streams returned by add_listener and add_named_listener should be polled regularly to avoid memory leaks.

LogObserver automatically detects and handles log file rotation and uses an appropriate character encoding on different platforms.

Each LogObserver has an associated background thread that does the actual reading. This thread is shut down after the LogObserver is dropped.

Implementations§

Source§

impl LogObserver

Source

pub fn new<P: AsRef<Path>>(path: P) -> LogObserver

Source

pub fn add_listener(&self) -> impl Stream<Item = LogEvent>

Returns a Stream of all LogEvents. To remove the listener simply drop the stream.

Internally the stream is backed by an unbound channel. This means it should be polled regularly to avoid memory leaks.

Source

pub fn add_named_listener( &self, name: impl Into<String>, ) -> impl Stream<Item = LogEvent>

Returns a Stream of LogEvents with executor equal to the given name. To remove the listener simply drop the stream.

This can be more memory efficient than add_listener, because only a small subset of LogEvents has to be buffered if not that many commands are executed with the given name.

Internally the stream is backed by an unbound channel. This means it should be polled regularly to avoid memory leaks.

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.