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
impl ToastLogger
Sourcepub fn builder() -> ToastLoggerBuilder
pub fn builder() -> ToastLoggerBuilder
Returns a ToastLoggerBuilder instance
that can build a ToastLogger with various configurations.
Examples found in repository?
More examples
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}Sourcepub fn flush() -> Result<()>
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§
Auto Trait Implementations§
impl !Freeze for ToastLogger
impl !RefUnwindSafe for ToastLogger
impl Send for ToastLogger
impl Sync for ToastLogger
impl Unpin for ToastLogger
impl !UnwindSafe for ToastLogger
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