How to filter the logs in log4j2
We have around 50 REST API(Connect-REST) calls and we would like to log the payload of only two api's into a separate log file because those two apis contains the sensitive information which is required for auditing. This file needs to be purged once in a week ..
I added below appender to log4j2.xml and able to capture the api payloads in separate file but I’m not able to filter the logs of specific API using the regex and also file is not getting deleted after 7 days ..
We have around 50 REST API(Connect-REST) calls and we would like to log the payload of only two api's into a separate log file because those two apis contains the sensitive information which is required for auditing. This file needs to be purged once in a week ..
I added below appender to log4j2.xml and able to capture the api payloads in separate file but I’m not able to filter the logs of specific API using the regex and also file is not getting deleted after 7 days ..
<RollingRandomAccessFile name="APPRESTAPI" fileName="${sys:pega.logdir}/APP-REST-API.log" filePattern="${sys:pega.logdir}/APP-REST-API-%d{MM-dd-yyyy}-%i.log.gz"> <PatternLayout> <Pattern>%d [%20.20t] [%20.20X{tenantid}] [%20.20X{app}] (%30.30c{3}) %-5p %X{stack} %X{userid} - %m%n</Pattern> </PatternLayout> <RegexFilter regex=".* Rule-Connect-REST.ORG-Int-Payments .*" onMatch="ACCEPT" onMismatch="DENY"/> <Policies> <TimeBasedTriggeringPolicy /> <SizeBasedTriggeringPolicy size="250 MB"/> </Policies> <DefaultRolloverStrategy max="20"> <Delete basePath="${sys:pega.logdir}" maxDepth="1"> <IfFileName glob="APP-REST-API*.log.gz" /> <IfLastModified age="7d" /> </Delete> </DefaultRolloverStrategy>
</RollingRandomAccessFile>