I have a particular log line with some information, which needs be logged in to a different file for future use. I have already configured log4j.properties in my system to log necessary information.
Eg:-
[2017-07-28 20:33:07,798] INFO - 'john@doe.com' logged in at [2017-07-28 20:33:07,798+0530]
I have to filter out this and append to a org.apache.log4j.DailyRollingFileAppender
Appreciate any help.
Below is the solution for xml configuration. You can find the the details here. As an example you can specify two appenders: one for storing all the lines and one for storing your special lines. Then, for the appender storing your special lines set up the filter in the following way (example for a RollingFileAppender):
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/app-%d{MM-dd-yyyy}.log.gz">
<RegexFilter regex=".*logged in at.*" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</PatternLayout>
<TimeBasedTriggeringPolicy />
</RollingFile>
Also check this question where you can find the clue on how to configure the same using properties.