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
impl LogObserver
pub fn new<P: AsRef<Path>>(path: P) -> LogObserver
Sourcepub fn add_listener(&self) -> impl Stream<Item = LogEvent>
pub fn add_listener(&self) -> impl Stream<Item = LogEvent>
Sourcepub fn add_named_listener(
&self,
name: impl Into<String>,
) -> impl Stream<Item = LogEvent>
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.