onAverageEvery

public abstract API onAverageEvery(int n)

Modifies the current log statement to be emitted with likelihood 1 in n. For example, inserting onAverageEvery(20) into a call chain results in approximately 5% as many messages being emitted as before. Unlike the other rate-limiting options, there is no guarantee about when the first such message will be emitted, though it becomes highly likely as the number of calls reaches several times n.

Notes

If multiple rate limiters are used for a single log statement, that log statement will only be emitted once all rate limiters have reached their threshold, and when a log statement is emitted all the rate limiters are reset. In particular for onAverageEvery(N) this means that logs may occurs less frequently than one-in-N if other rate limiters are active.

When rate limiting is active, a "skipped" count is added to log statements to indicate how many logs were disallowed since the last log statement was emitted.

If this method is called multiple times for a single log statement, the last invocation will take precedence.

Parameters

n

the factor by which to reduce logging frequency; a value of 1 has no effect.

Throws

if n is not positive.