title: In Log4j2, Is it possible to filter out certain key value pairs from the logger based on the key?
body: <p>Can Log4j2 be configured in such a way that the filters or some other components can filter out certain values from getting printed in the log? (but should allow other fields in the same line to pass through)</p>
  
  <p>Say the following lines appear in the log</p>
  
  <pre><code> [operation=DONE, userName=junitUser, tenant=Tenant [tenantID=default], needDetails=1, message=BaseMsg [version=1.0, sdk=AppSDK [version=1.3, protocols=[4aac81ca, 393ae7a0]], device=Device [id=12345, type=Pompom, info=Dot's Device]]], channel=null
   [operation=DONE, userName=junitUser224, tenant=Tenant [tenantID=default], needDetails=1, message=BaseMsg [version=1.0, sdk=AppSDK [version=1.3, protocols=[4aac81ca,393ae7a0]], device=Device [id=123456, type=Mamamia, info=tom's Device]]], channel=null
  </code></pre>
  
  <p>Now can I filter out the "userName" field in such a way that the log lines now do not contain it as shown below?</p>
  
  <pre><code> [operation=DONE, tenant=Tenant [tenantID=default], needDetails=1, message=BaseMsg [version=1.0, sdk=AppSDK [version=1.3, protocols=[4aac81ca, 393ae7a0]], device=Device [id=12345, type=Pompom, info=Dot's Device]]], channel=null
   [operation=DONE, tenant=Tenant [tenantID=default], needDetails=1, message=BaseMsg [version=1.0, sdk=AppSDK [version=1.3, protocols=[4aac81ca,393ae7a0]], device=Device [id=123456, type=Mamamia, info=tom's Device]]], channel=null
  </code></pre>
  
  <p>Here is my log4j2.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="WARN"&gt;
    &lt;Appenders&gt;
      &lt;Console name="Console" target="SYSTEM_OUT"&gt;
        &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/&gt;
      &lt;/Console&gt;
      &lt;RollingFile name="RollingFile" fileName="/Users/dunston/logs/app.log"
                   filePattern="logs/app-%d{MM-dd-yyyy}.log.gz"&gt;
          &lt;RegexFilter regex=".* zinger_log .*" onMatch="ACCEPT" onMismatch="DENY"/&gt;
  
        &lt;PatternLayout&gt;
          &lt;pattern&gt;%d %p %c{1.} [%t] %m%n&lt;/pattern&gt;
        &lt;/PatternLayout&gt;
        &lt;TimeBasedTriggeringPolicy /&gt;
      &lt;/RollingFile&gt;
    &lt;/Appenders&gt;
      &lt;Loggers&gt;
      &lt;Root level="debug"&gt;
        &lt;AppenderRef ref="Console"/&gt;
        &lt;AppenderRef ref="RollingFile"/&gt;         
      &lt;/Root&gt;
    &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>