java - How to use Log4j2 xml Rewrite appender for modifying LogEvent before it logs in file -


i want use rewrite appender in log4j2.xml file before logging can modify logs. have not helps google. per log4j2 documents rewrite interface has rewrite method , maprewritepolicy implementation class, when run able see web3.log file generating not seeing modification in log content. seen maprewritepolicy source code , created local implementation class maprewritepolicyimpl.java in project , put system.out see code flow coming class log4j2.xml file. have modified log4j2.xml use maprewritepolicyimpl.java code flow not going maprewritepolicyimpl.java class.

<rewrite name="rewrite" >             <appender-ref ref="web3" />              <maprewritepolicyimpl">                 <keyvaluepair key="creditcard" value="new12345"/>             </maprewritepolicyimpl>          </rewrite>        <configuration monitorinterval="5" status="debug" strict="true">         <appenders>             <rollingfile name="web3" filename="../logs/web3.log"                  filepattern="${sys:catalina.home}/logs/$${date:yyyy-mm-dd}/web3-%d{yyyy-mm-dd}-%i.log.gz">                 <patternlayout                     pattern="%d{dd/mm/yyyy hh:mm:ss,sss} [%x{cartid}] [%x{sessionid}] [%p] [%t] [%c] (%f:%l)  - %m%n" />                 <policies>                     <timebasedtriggeringpolicy interval="1"                         modulate="true" />                     <sizebasedtriggeringpolicy size="10 mb" />                  </policies>             </rollingfile>             <rewrite name="rewrite" >                 <appender-ref ref="web3" />                  <maprewritepolicy">                     <keyvaluepair key="creditcard" value="new12345"/>                 </maprewritepolicy>              </rewrite>     </appenders>     <loggers>         <logger name="com.virginamerica" level="info" additivity="false">             <!-- <appender-ref ref="web3" /> -->             <appender-ref ref="rewrite"/>         </logger>     </loggers> </configuration> 

maprewritepolicy evaluate logevents contain mapmessage , add or update elements of map. works if application calls logger.info(new mapmessage(keyvaluemap)). suspect not application doing.

usually, messages either simplemessage (if called logger.info("just string without parameters")) or parameterizedmessage (if called logger.info("hi {}!", name)). rewriteappender not able either simplemessage or parameterizedmessages, nothing replaced...

you may want take @ documentation patternlayout: has capability replace regular expressions in string messages replacement value, if use replace{pattern}{regex}{substitution} pattern.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -