Log4j2 : Changing log level for a specific user and specific loggers : not working as expected

Requirement is to change the log level for a specific user . Using DynamicThresholdFilter at the context level does work but applies to all the loggers . My requirement is to only apply it for specific loggers and not impact the others. With this configuration file all the appenders are logging at debug levell.

This is how my file looks like . Any recommendations on applying the same filter or any other filter which can enable debug logging for specific loggers ?

<?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO" monitorInterval="30">     <Properties>         ---------------------     </Properties>     <DynamicThresholdFilter         key="customLogging-enabled" onMatch="ACCEPT" onMismatch="DENY">         <KeyValuePair key="true" value="DEBUG" />     </DynamicThresholdFilter>     <Appenders>         <Console name="consoleAppender" target="SYSTEM_OUT"             follow="true">             <PatternLayout pattern="${CONSOLE_LOG_PATTERN}" />         </Console>          <RollingFile name="customLoggingAppender"             fileName="${sys:log_dir}/customLogging.log"             filePattern="customLogging-%d{yyyy-MM-dd}-%i.log" append="true">             <ThreadContextMapFilter onMatch="DENY"                 onMismatch="NEUTRAL">                 <KeyValuePair key="customLogging-enabled" value="true" />             </ThreadContextMapFilter>             <PatternLayout>                 .......................             </PatternLayout>             <Policies>                 <SizeBasedTriggeringPolicy size="5000KB" />             </Policies>             <DefaultRolloverStrategy max="20" />         </RollingFile>          <RollingFile name="standardAppender"             fileName="${sys:log_dir}/standard.log"             filePattern="standard-%d{yyyy-MM-dd}-%i.log" append="true">             <PatternLayout>                 ....................             </PatternLayout>             <Policies>                 <SizeBasedTriggeringPolicy size="5000KB" />             </Policies>             <DefaultRolloverStrategy max="20" />         </RollingFile>          .......More appenders here      </Appenders>     <Loggers>          <Root level="ERROR">             <AppenderRef ref="consoleAppender" />             <AppenderRef ref="standardAppender" />         </Root>          <!-- DEFAULTED TO ROOT LOGGER - START -->         <Logger name="com.abc" level="ERROR">             <AppenderRef ref="customLoggingAppender" />         </Logger>          <Logger name="com.abc.helpers" level="ERROR">             <AppenderRef ref="customLoggingAppender" />         </Logger>          <Logger name="com.abc.business.persist.utils" level="ERROR" />          <Logger             name="com.abc.business.persist.ManagerFactory"             level="ERROR" />          <Logger name="com.da.handlers" level="ERROR" additivity="false">             <AppenderRef ref="abcAppender" />             <AppenderRef ref="customLoggingAppender" />         </Logger>          <Logger name="com.handler.audit" level="ERROR"             additivity="false">             <AppenderRef ref="xyzAppender" />         </Logger>     </Loggers> </Configuration> 

I tried applying the same filter at the appender level but it did not work

<RollingFile name="customLoggingAppender" fileName="${sys:log_dir}/customLogging.log" filePattern="customLogging-%d{yyyy-MM-dd}-%i.log" append="true">             <DynamicThresholdFilter key="customLogging-enabled" onMatch="ACCEPT" onMismatch="DENY">               <KeyValuePair key="true" value="DEBUG"/>             </DynamicThresholdFilter>             <PatternLayout>                ....             </PatternLayout>             <Policies>                 <SizeBasedTriggeringPolicy size="5000KB" />             </Policies>             <DefaultRolloverStrategy max="20" />              </RollingFile> 

My expectation is that ONLY the loggers referring to this appender will be logging at debug level

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.