pub struct LoggerGuard { /* private fields */ }Expand description
Keeps background logging alive; returned by Logger::init.
File output is written by a background thread. This guard owns that thread:
when it is dropped, every line still queued is flushed to the file and the
thread stops. Hold it until the program ends, typically as the first binding
in main:
use tiny_tracing::{Logger, Output};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let _guard = Logger::new()
.with_output(Output::File("app.log".into()))
.init()?;
tiny_tracing::info!("this line is flushed when `_guard` is dropped");
Ok(())
}Do not bind it to a bare _: let _ = Logger::new().init()?; drops it
immediately and file output stops. Also note that std::process::exit skips
destructors, so lines still queued at that point are lost.
For Output::Stdout and Output::Stderr the guard holds nothing, but
keeping it costs nothing and keeps the code independent of the output.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for LoggerGuard
impl !UnwindSafe for LoggerGuard
impl Freeze for LoggerGuard
impl Send for LoggerGuard
impl Sync for LoggerGuard
impl Unpin for LoggerGuard
impl UnsafeUnpin for LoggerGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more