apache / apache/logging-log4j2

Will Log4j2 support pre-level-check dynamic log filtering (similar to Logback's TurboFilter

Open
#3,848 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

I’ve been researching per-request dynamic logging and came across a limitation in Log4j2’s filtering model compared to Logback.

In Logback, the TurboFilter feature allows log events to be conditionally filtered before the logger’s level check is applied. This enables powerful use cases like enabling DEBUG logs for specific requests, even when the logger’s configured level is INFO.

From my understanding and recent testing, Log4j2 does not currently support this behavior. Specifically:

If a logger is configured at INFO, then all DEBUG messages are short-circuited before any Filter or ThreadContext logic is evaluated.

As a result, it's not currently possible to emit DEBUG logs on a per-request basis using MDC or filters without globally lowering the logger level to DEBUG first.

My question is:

Are there any plans for Log4j2 to support pre-level-check filtering (similar to Logback’s TurboFilter), to allow dynamic log level evaluation per request or thread context?

I understand this design may be for performance reasons, but it would be helpful to know if this kind of feature is on the roadmap or technically feasible within the current architecture.

Thank you for your excellent work on Log4j2, and I appreciate your time and insights.

Best regards,

Amy

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.