GitHub user ppkarwasz added a comment to the discussion: How to change log 
level dynamically per request level?

Hi @little-hue,

A `DynamicThresholdFilter` can be used to override the level check on the root 
logger, but there are a couple of important caveats:

* The filter must be defined as a **global filter** (a direct child of 
`<Configuration>`), not attached to an appender, appender reference or logger.
* The filter must return `ACCEPT` for the event to pass through.

Log4j Core evaluates filters in a strict order. The initial level check on the 
logger happens very early in the process, so filters attached lower in the 
chain (e.g., on the root logger or an appender) cannot influence that decision. 
That’s why placing the `DynamicThresholdFilter` at the global level is 
essential.

You can find more detail in the [Log4j 2 filter 
documentation](https://logging.apache.org/log4j/2.x/manual/filters.html), which 
explains the evaluation order and scope of filters in different positions on 
the logging pipeling


GitHub link: 
https://github.com/apache/logging-log4j2/discussions/3917#discussioncomment-14347631

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to