-
Notifications
You must be signed in to change notification settings - Fork 884
Open
Description
Feature Request
Motivation
Hi team, some other logging libraries (i.e., glog) supports log every N: https://github.com/google/glog/blob/53d58e4531c7c90f71ddab503d915e027432447a/src/glog/logging.h#L962-L963 I'm wondering if we could support that as well.
The main benefit of which is, on heavy logging our logging won't spam the output, and potentially improve the performance as well.
Proposal
macro_rules! log_every_n {
($n:expr, $($arg:tt)*) => {
static COUNTER: AtomicU64 = AtomicU64::new(0);
let count = COUNTER.fetch_add(1, Ordering::Relaxed);
if count % $n == 0 {
$($arg)*
}
};
}
// Usage
log_every_n!(100, warn!("Reject request due to memory limit exceeded"));Alternatives
N/A
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels