log4j properties BurstFilter configuration
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
BurstFilter in Log4j 2 is a rate limiter for log events. It is useful when one noisy code path can flood the console or a file appender and bury the signals you actually care about. In a log4j2.properties configuration, the filter is straightforward to attach once you understand what rate, maxBurst, and level actually mean.
What BurstFilter Does
BurstFilter limits how quickly matching events are allowed through. It is designed for the "something is failing in a tight loop" case, where thousands of similar log lines can appear in a few seconds.
The important behavior is severity-based:
- events more severe than the configured
levelcontinue to pass - events at that level or below are subject to burst limiting
That means a configuration with level = INFO mainly protects you from floods of INFO, DEBUG, and TRACE style traffic while still allowing WARN, ERROR, and FATAL events through.
Configuring It in log4j2.properties
The filter is usually attached to an appender. In the example below, a console appender allows short bursts of INFO traffic, then starts suppressing matching events if they keep arriving too fast.
With this configuration, the appender can accept a burst of up to 20 matching events, then sustain roughly 5 per second over time. Exact behavior depends on event timing, but the general effect is that repeated low-value log storms get trimmed.
How to Tune rate and maxBurst
Think of rate as the long-term allowance and maxBurst as the short spike allowance.
- '
ratecontrols the steady-state flow.' - '
maxBurstcontrols how much traffic can pass before limiting becomes noticeable.'
If your application logs brief startup chatter and then quiets down, a moderate maxBurst with a conservative rate usually works well. If you have traffic spikes during deploys or cache warm-up, raising maxBurst may be necessary so normal bursts do not get suppressed.
Tune with real workloads, not guesses. A filter that is too strict hides useful context, while a filter that is too loose does almost nothing.
Appender Placement Matters
Attach the filter as close as possible to the noisy destination. Putting BurstFilter on a specific appender lets you protect one sink without changing every logger in the system. That is often better than a broad root-level strategy.
For example, you might want burst limiting on the console in development, but a less aggressive file appender in production. Filters attached directly to appenders make that separation easy.
Also note the distinction between Log4j configuration properties and JVM system properties. BurstFilter is configured inside log4j2.properties. It is not something you normally define with a -D flag except for the usual setting that points Log4j at the configuration file itself.
Common Pitfalls
The first pitfall is misunderstanding the level setting. Many developers expect level = WARN to rate-limit warnings and errors together. In practice, more severe events continue to pass, so choose the threshold based on what noise you want to suppress.
Another pitfall is setting rate too low in an effort to keep logs quiet. That can remove the very sequence you need to debug an incident. Start with a gentle limit, then tighten it only after observing real output.
A third mistake is attaching the filter to the wrong component. If the noisy traffic comes from one appender but the filter is declared somewhere else, the configuration will load yet the observed behavior will not change. When debugging, confirm the filter is bound to the appender that actually writes the log lines you are watching.
Finally, BurstFilter is not a substitute for fixing spammy logging code. If a loop writes the same INFO message ten thousand times, the real repair is often to change the application logic or lower the log level at the source.
Summary
- '
BurstFilterlimits bursts of lower-severity log events so one noisy path does not overwhelm the sink.' - In
log4j2.properties, attach it directly to the target appender. - '
ratecontrols steady throughput andmaxBurstcontrols short spikes.' - More severe events than the configured
levelstill pass through. - Tune the filter with real log traffic and treat it as a safeguard, not a replacement for better logging design.

