ToastLogger

Struct ToastLogger 

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

log crate logger that implements log::Log trait. It sends the logging output to the Windows Toast Notifications.

§Examples

  ToastLogger::builder()
      .max_level(log::LevelFilter::Info)
      .init()?;
  log::info!("Test info log");  // Shows a Windows Toast Notification.

Implementations§

Source§

impl ToastLogger

Source

pub fn builder() -> ToastLoggerBuilder

Returns a ToastLoggerBuilder instance that can build a ToastLogger with various configurations.

Examples found in repository?
examples/multi.rs (line 6)
5pub fn main() -> Result<()> {
6    ToastLogger::builder()
7        .max_level(log::LevelFilter::Info)
8        .init()?;
9
10    for arg in env::args().skip(1) {
11        log::info!("{}", arg);
12    }
13    Ok(())
14}
More examples
Hide additional examples
examples/echo.rs (line 6)
5pub fn main() -> Result<()> {
6    ToastLogger::builder()
7        .max_level(log::LevelFilter::Info)
8        .init()?;
9
10    let args: Vec<String> = env::args().skip(1).collect();
11    log::info!("{}", args.join("\n"));
12    Ok(())
13}
examples/auto_flush.rs (line 6)
5pub fn main() -> Result<()> {
6    ToastLogger::builder()
7        .max_level(log::LevelFilter::Info)
8        .auto_flush(false)
9        .init()?;
10
11    for arg in env::args().skip(1) {
12        log::info!("{}", arg);
13    }
14    ToastLogger::flush()?;
15    Ok(())
16}
examples/expire.rs (line 13)
5pub fn main() -> anyhow::Result<()> {
6    let args: Vec<String> = env::args().skip(1).collect();
7    let duration = if args.is_empty() {
8        Duration::ZERO
9    } else {
10        Duration::from_secs(args[0].parse()?)
11    };
12
13    let mut builder = ToastLogger::builder();
14    let message = if duration.is_zero() {
15        "This message shouldn't expire".into()
16    } else {
17        let message = format!("This message should expire in {duration:?}.");
18        builder.create_notification(move |records| {
19            let mut notification = Notification::new_with_records(records)?;
20            notification.expires_in(duration)?;
21            Ok(notification)
22        });
23        message
24    };
25    builder.max_level(log::LevelFilter::Info).init()?;
26
27    log::info!("{}", message);
28    Ok(())
29}
Source

pub fn flush() -> Result<()>

Flush the internal log buffer. If the buffer is not empty, this function shows one toast notification by concatenating all logs in the buffer.

Please see ToastLoggerBuilder::auto_flush() for more details.

Examples found in repository?
examples/auto_flush.rs (line 14)
5pub fn main() -> Result<()> {
6    ToastLogger::builder()
7        .max_level(log::LevelFilter::Info)
8        .auto_flush(false)
9        .init()?;
10
11    for arg in env::args().skip(1) {
12        log::info!("{}", arg);
13    }
14    ToastLogger::flush()?;
15    Ok(())
16}

Trait Implementations§

Source§

impl Log for ToastLogger

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,