WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f08ad6a

Browse files
authored
feat: add tracing logs to remaining files (#48)
close #37
1 parent d5532a4 commit f08ad6a

File tree

3 files changed

+71
-17
lines changed

3 files changed

+71
-17
lines changed

notify-debouncer-full/src/lib.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,29 @@ where
130130
#[cfg(feature = "crossbeam-channel")]
131131
impl DebounceEventHandler for crossbeam_channel::Sender<DebounceEventResult> {
132132
fn handle_event(&mut self, event: DebounceEventResult) {
133-
let _ = self.send(event);
133+
let result = self.send(event);
134+
if let Err(e) = result {
135+
tracing::error!(?e, "failed to send debounce event result");
136+
}
134137
}
135138
}
136139

137140
#[cfg(feature = "flume")]
138141
impl DebounceEventHandler for flume::Sender<DebounceEventResult> {
139142
fn handle_event(&mut self, event: DebounceEventResult) {
140-
let _ = self.send(event);
143+
let result = self.send(event);
144+
if let Err(e) = result {
145+
tracing::error!(?e, "failed to send debounce event result");
146+
}
141147
}
142148
}
143149

144150
impl DebounceEventHandler for std::sync::mpsc::Sender<DebounceEventResult> {
145151
fn handle_event(&mut self, event: DebounceEventResult) {
146-
let _ = self.send(event);
152+
let result = self.send(event);
153+
if let Err(e) = result {
154+
tracing::error!(?e, "failed to send debounce event result");
155+
}
147156
}
148157
}
149158

@@ -214,7 +223,7 @@ impl<T: FileIdCache> DebounceDataInner<T> {
214223

215224
if let Some(event) = self.rescan_event.take() {
216225
if now.saturating_duration_since(event.time) >= self.timeout {
217-
tracing::trace!("debounced event: {event:?}");
226+
tracing::trace!("debounce candidate rescan event: {event:?}");
218227
events_expired.push(event);
219228
} else {
220229
self.rescan_event = Some(event);
@@ -229,6 +238,7 @@ impl<T: FileIdCache> DebounceDataInner<T> {
229238
while let Some(event) = queue.events.pop_front() {
230239
// remove previous event of the same kind
231240
if let Some(idx) = kind_index.get(&event.kind).copied() {
241+
tracing::trace!("removed candidate event: {event:?}");
232242
events_expired.remove(idx);
233243

234244
kind_index.values_mut().for_each(|i| {
@@ -239,6 +249,7 @@ impl<T: FileIdCache> DebounceDataInner<T> {
239249
}
240250

241251
if now.saturating_duration_since(event.time) >= self.timeout {
252+
tracing::trace!("debounce candidate event: {event:?}");
242253
kind_index.insert(event.kind, events_expired.len());
243254

244255
events_expired.push(event);
@@ -553,7 +564,10 @@ impl<T: Watcher, C: FileIdCache> Debouncer<T, C> {
553564
pub fn stop(mut self) {
554565
self.set_stop();
555566
if let Some(t) = self.debouncer_thread.take() {
556-
let _ = t.join();
567+
let result = t.join();
568+
if let Err(e) = result {
569+
tracing::error!(?e, "failed to join debouncer thread");
570+
}
557571
}
558572
}
559573

@@ -634,6 +648,7 @@ impl<T: Watcher, C: FileIdCache> Drop for Debouncer<T, C> {
634648
/// Timeout is the amount of time after which a debounced event is emitted.
635649
///
636650
/// If `tick_rate` is `None`, notify will select a tick rate that is 1/4 of the provided timeout.
651+
#[tracing::instrument(level = "debug", skip(event_handler, file_id_cache))]
637652
pub fn new_debouncer_opt<F: DebounceEventHandler, T: Watcher, C: FileIdCache + Send + 'static>(
638653
timeout: Duration,
639654
tick_rate: Option<Duration>,
@@ -730,6 +745,7 @@ pub fn new_debouncer<F: DebounceEventHandler>(
730745
)
731746
}
732747

748+
#[tracing::instrument(level = "trace", ret)]
733749
fn sort_events(events: Vec<DebouncedEvent>) -> Vec<DebouncedEvent> {
734750
let mut sorted = Vec::with_capacity(events.len());
735751

notify-debouncer-mini/src/lib.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,29 @@ where
158158
#[cfg(feature = "crossbeam-channel")]
159159
impl DebounceEventHandler for crossbeam_channel::Sender<DebounceEventResult> {
160160
fn handle_event(&mut self, event: DebounceEventResult) {
161-
let _ = self.send(event);
161+
let result = self.send(event);
162+
if let Err(e) = result {
163+
tracing::error!(?e, "failed to send debounce event result");
164+
}
162165
}
163166
}
164167

165168
#[cfg(feature = "flume")]
166169
impl DebounceEventHandler for flume::Sender<DebounceEventResult> {
167170
fn handle_event(&mut self, event: DebounceEventResult) {
168-
let _ = self.send(event);
171+
let result = self.send(event);
172+
if let Err(e) = result {
173+
tracing::error!(?e, "failed to send debounce event result");
174+
}
169175
}
170176
}
171177

172178
impl DebounceEventHandler for std::sync::mpsc::Sender<DebounceEventResult> {
173179
fn handle_event(&mut self, event: DebounceEventResult) {
174-
let _ = self.send(event);
180+
let result = self.send(event);
181+
if let Err(e) = result {
182+
tracing::error!(?e, "failed to send debounce event result");
183+
}
175184
}
176185
}
177186

@@ -329,11 +338,15 @@ impl<T: Watcher> Debouncer<T> {
329338
impl<T: Watcher> Drop for Debouncer<T> {
330339
fn drop(&mut self) {
331340
// send error just means that it is stopped, can't do much else
332-
let _ = self.stop_channel.send(InnerEvent::Shutdown);
341+
let result = self.stop_channel.send(InnerEvent::Shutdown);
342+
if let Err(e) = result {
343+
tracing::error!(?e, "failed to send shutdown event");
344+
}
333345
}
334346
}
335347

336348
/// Creates a new debounced watcher with custom configuration.
349+
#[tracing::instrument(level = "debug", skip(event_handler))]
337350
pub fn new_debouncer_opt<F: DebounceEventHandler, T: Watcher>(
338351
config: Config,
339352
mut event_handler: F,
@@ -383,7 +396,10 @@ pub fn new_debouncer_opt<F: DebounceEventHandler, T: Watcher>(
383396
move |e: Result<Event, Error>| {
384397
// send failure can't be handled, would need a working channel to signal that
385398
// also probably means that we're in the process of shutting down
386-
let _ = tx_c.send(InnerEvent::NotifyEvent(e));
399+
let result = tx_c.send(InnerEvent::NotifyEvent(e));
400+
if let Err(e) = result {
401+
tracing::error!(?e, "failed to send notify event");
402+
}
387403
},
388404
config.notify_config,
389405
)?;

notify/src/poll.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::{
1010
sync::{
1111
Arc, Mutex,
1212
atomic::{AtomicBool, Ordering},
13+
mpsc,
1314
},
1415
thread,
1516
time::Duration,
@@ -39,20 +40,29 @@ where
3940
#[cfg(feature = "crossbeam-channel")]
4041
impl ScanEventHandler for crossbeam_channel::Sender<ScanEvent> {
4142
fn handle_event(&mut self, event: ScanEvent) {
42-
let _ = self.send(event);
43+
let result = self.send(event);
44+
if let Err(e) = result {
45+
tracing::error!(?e, "failed to send scan event result");
46+
}
4347
}
4448
}
4549

4650
#[cfg(feature = "flume")]
4751
impl ScanEventHandler for flume::Sender<ScanEvent> {
4852
fn handle_event(&mut self, event: ScanEvent) {
49-
let _ = self.send(event);
53+
let result = self.send(event);
54+
if let Err(e) = result {
55+
tracing::error!(?e, "failed to send scan event result");
56+
}
5057
}
5158
}
5259

5360
impl ScanEventHandler for std::sync::mpsc::Sender<ScanEvent> {
5461
fn handle_event(&mut self, event: ScanEvent) {
55-
let _ = self.send(event);
62+
let result = self.send(event);
63+
if let Err(e) = result {
64+
tracing::error!(?e, "failed to send scan event result");
65+
}
5666
}
5767
}
5868

@@ -573,7 +583,7 @@ impl PollWatcher {
573583
let want_to_stop = Arc::clone(&self.want_to_stop);
574584
let delay = self.delay;
575585

576-
let _ = thread::Builder::new()
586+
let result = thread::Builder::new()
577587
.name("notify-rs poll loop".to_string())
578588
.spawn(move || {
579589
loop {
@@ -596,13 +606,22 @@ impl PollWatcher {
596606
}
597607
}
598608
// TODO: v7.0 use delay - (Instant::now().saturating_duration_since(start))
599-
if let Some(delay) = delay {
600-
let _ = rx.recv_timeout(delay);
609+
let result = if let Some(delay) = delay {
610+
rx.recv_timeout(delay).or_else(|e| match e {
611+
mpsc::RecvTimeoutError::Timeout => Ok(()),
612+
mpsc::RecvTimeoutError::Disconnected => Err(mpsc::RecvError),
613+
})
601614
} else {
602-
let _ = rx.recv();
615+
rx.recv()
616+
};
617+
if let Err(e) = result {
618+
tracing::error!(?e, "failed to receive poll message");
603619
}
604620
}
605621
});
622+
if let Err(e) = result {
623+
tracing::error!(?e, "failed to start poll watcher thread");
624+
}
606625
}
607626

608627
/// Watch a path location.
@@ -647,16 +666,19 @@ impl PollWatcher {
647666

648667
impl Watcher for PollWatcher {
649668
/// Create a new [`PollWatcher`].
669+
#[tracing::instrument(level = "debug", skip(event_handler))]
650670
fn new<F: EventHandler>(event_handler: F, config: Config) -> crate::Result<Self> {
651671
Self::new(event_handler, config)
652672
}
653673

674+
#[tracing::instrument(level = "debug", skip(self))]
654675
fn watch(&mut self, path: &Path, watch_mode: WatchMode) -> crate::Result<()> {
655676
self.watch_inner(path, watch_mode);
656677

657678
Ok(())
658679
}
659680

681+
#[tracing::instrument(level = "debug", skip(self))]
660682
fn unwatch(&mut self, path: &Path) -> crate::Result<()> {
661683
self.unwatch_inner(path)
662684
}

0 commit comments

Comments
 (0)