[ 
https://issues.apache.org/jira/browse/LOG4J2-3455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17515084#comment-17515084
 ] 

Ralph Goers edited comment on LOG4J2-3455 at 3/31/22, 5:18 AM:
---------------------------------------------------------------

We are suggesting that you forget about your Log4j 1 customizations and focus 
on what Log4j 2 provides out of the box.  Instead, have your application do:
{code:java}
ThreadContext.put("LEVEL", threadLevel.toUpperCase());
{code}
Then you can use either the 
[DynamicThresholdFilter|https://logging.apache.org/log4j/2.x/manual/filters.html#DynamicThresholdFilter]
    
{code:java}
<DynamicThresholdFilter key="LEVEL" defaultThreshold="ERROR" onMatch="ACCEPT" 
onMismatch="NEUTRAL">
 <KeyValuePair key="TRACE" value="TRACE"/>
 <KeyValuePair key="DEBUG" value="DEBUG"/>
 <KeyValuePair key="INFO" value="INFO"/>
 <KeyValuePair key="WARN" value="WARN"/>
 <KeyValuePair key="ERROR" value="ERROR"/>
</DynamicThresholdFilter> {code}
or you can create your own custom Filter. You DO NOT need a custom Logger.

Note that it is quite common to create a servlet filter that inspects the 
incoming headers and sets ThreadContext values accordingly, remembering to 
clear it when the request completes.

 


was (Author: [email protected]):
We are suggesting that you forget about your Log4j 1 customizations and focus 
on what Log4j 2 provides out of the box.  Instead, have your application do:
{code:java}
ThreadContext.put("LEVEL", threadLevel.toUpperCase());
{code}
Then you can use either the 
[DynamicThresholdFilter|https://logging.apache.org/log4j/2.x/manual/filters.html#DynamicThresholdFilter]
    
{code:java}
<DynamicThresholdFilter key="LEVEL" defaultThreshold="ERROR" onMatch="ACCEPT" 
onMismatch="NEUTRAL">
 <KeyValuePair key="TRACE" value="TRACE"/>
 <KeyValuePair key="DEBUG" value="DEBUG"/>
 <KeyValuePair key="INFO" value="INFO"/>
 <KeyValuePair key="WARN" value="WARN"/>
 <KeyValuePair key="ERROR" value="ERROR"/>
</DynamicThresholdFilter> {code}
or you can create your own custom Filter. You DO NOT need a custom Logger.

 

> Log4j 1.x 2.17.2 bridge - Thread specific Log Level Threshold doesn't work
> --------------------------------------------------------------------------
>
>                 Key: LOG4J2-3455
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3455
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.17.2
>            Reporter: Pooja Pandey
>            Priority: Major
>         Attachments: CustomLogger.java, CustomLoggerFactory.java, 
> CustomMultiProcessRollingAppender.java, ThreadLevelLogThresholdTest.java, 
> customlog.properties
>
>
> In our application we have migrated from log4j1.x to log4j1.x 2.17.2 bridge. 
> With bridge 2.17.2/2.17.3-SNAPSHOT, thread specific log level threshold 
> doesn't work which used to work earlier with log4j1.x. We had achieved this 
> feature by overriding getEffectiveLevel(), but now this doesn't work anymore 
> with log4j1.x bridge since the method getEffectiveLevel() is not getting 
> invoked to set effective level.
>  
>  For reference, Java class files for Custom Logger, Custom Multiprocess 
> Rolling Appender and Test program are attached along with cutom log4j 
> properties 
> file.[^CustomLogger.java][^customlog.properties][^ThreadLevelLogThresholdTest.java]



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to