in logger/src/single.rs [28:60]
fn log(&self, record: &log::Record<'_>) {
// If the log message is filtered by the log level, return early.
if !self.enabled(record.metadata()) {
return;
}
// Tries to re-use a buffer from the pool or allocate a new buffer to
// to avoid blocking and try to avoid dropping the message. Message may
// still be dropped if the log_filled queue is full.
let mut buffer = self
.log_cleared
.pop()
.unwrap_or_else(|| Vec::with_capacity(self.buffer_size));
// Write the log message into the buffer and send to the receiver
if (self.format)(&mut buffer, DateTime::recent(), record).is_ok() {
let bytes = buffer.len();
// Note this may drop a log message, but avoids blocking. The
// preference here is to preserve log messages which lead up to the
// point where we begin to drop log messages. For example, if an
// error begins to happen which causes very many log messages, it is
// more beneficial to have the history leading up to the issue than
// to preserve more recent error messages.
if self.log_filled.push(buffer).is_ok() {
LOG_WRITE.increment();
LOG_WRITE_BYTE.add(bytes as _);
} else {
LOG_DROP.increment();
LOG_DROP_BYTE.add(bytes as _);
}
}
}