1extern crate slog;
16extern crate notify_rust;
17
18use notify_rust::Notification;
19use notify_rust::hints::NotificationHint;
20
21pub struct Notify{
22 name: &'static str
23}
24
25impl slog::Drain for Notify{
26 type Err = String;
27 type Ok = ();
28
29 fn log(&self, info: &slog::Record, _: &slog::OwnedKVList) -> Result<Self::Ok, Self::Err>{
30 let summary = format!("{:?} {}@{}:{}", info.level(), info.file(), info.line(), info.column());
31 let body = format!("{}", info.msg());
32
33 let mut notification = Notification::new();
34 notification
35 .appname(self.name)
36 .summary(&summary)
37 .body(&body);
38
39 if info.level().is_at_least(slog::Level::Warning){
40 notification.hint(NotificationHint::Resident(true));
41 }
42
43 notification
44 .show()
45 .unwrap();
46 Ok(())
47 }
48}
49
50pub fn simple(name: &'static str) -> Notify {
51 Notify{
52 name: name
53 }
54}