Skip to content

Commit 77f96ae

Browse files
committed
Do not track dirty state in logger
We don't regularly drop the inner logger, so one additional flush doesn't justify the added complexity. Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 1a27fee commit 77f96ae

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

logging/src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ struct LoggerInner<CB: ContainerBuilder, A: ?Sized + FnMut(&Duration, &mut Optio
113113
offset: Duration,
114114
/// container builder to produce buffers of accumulated log events
115115
builder: CB,
116-
/// True if we logged an event since the last flush.
117-
/// Used to avoid flushing buffers on drop.
118-
dirty: bool,
119116
/// action to take on full log buffers, or on flush.
120117
action: A,
121118
}
@@ -131,7 +128,6 @@ impl<CB: ContainerBuilder> Logger<CB> {
131128
offset,
132129
action,
133130
builder: CB::default(),
134-
dirty: false,
135131
};
136132
let inner = Rc::new(RefCell::new(inner));
137133
Logger { inner }
@@ -243,7 +239,6 @@ impl<CB: ContainerBuilder, A: ?Sized + FnMut(&Duration, &mut Option<CB::Containe
243239
{
244240
let elapsed = self.time.elapsed() + self.offset;
245241
for event in events {
246-
self.dirty = true;
247242
self.builder.push_into((elapsed, event.into()));
248243
while let Some(container) = self.builder.extract() {
249244
let mut c = Some(std::mem::take(container));
@@ -270,18 +265,13 @@ impl<CB: ContainerBuilder, A: ?Sized + FnMut(&Duration, &mut Option<CB::Containe
270265

271266
// Send no container to indicate flush.
272267
(self.action)(&elapsed, &mut None);
273-
274-
self.dirty = false;
275268
}
276269
}
277270

278271
/// Flush on the *last* drop of a logger.
279272
impl<CB: ContainerBuilder, A: ?Sized + FnMut(&Duration, &mut Option<CB::Container>)> Drop for LoggerInner<CB, A> {
280273
fn drop(&mut self) {
281-
// Avoid sending out empty buffers just because of drops.
282-
if self.dirty {
283-
self.flush();
284-
}
274+
self.flush();
285275
}
286276
}
287277

@@ -293,7 +283,6 @@ where
293283
f.debug_struct("LoggerInner")
294284
.field("time", &self.time)
295285
.field("offset", &self.offset)
296-
.field("dirty", &self.dirty)
297286
.field("action", &"FnMut")
298287
.field("builder", &self.builder)
299288
.finish()

0 commit comments

Comments
 (0)