My Java project contains following packages
- com.main.log4j.main , com.main.log4j.other.
As per my requirement, I have to exclude all log lines of package "com.main.log4j.other" from console and created a new log file "OTHER_LOG.log"
The below config.xml is working properly.
Now, I want, if it ("OTHER_LOG.log") exceeds certain size lets say 1 MB, it will create new file, keeping the previous file as backup but with timestamp.
Like, "OTHER_LOG.20190221155085.log"
That's why I have added "rollingPolicy", "triggeringPolicy".
But It gives warning -
log4j:WARN Unrecognized element rollingPolicy
log4j:WARN Unrecognized element triggeringPolicy
<appender name="CONSOLE-LOG" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="..." />
</layout>
</appender>
<appender name="OTHER-LOG"
class="org.apache.log4j.FileAppender">
<param name="Threshold" value="DEBUG" />
<param name="File" value="logs/OTHER_LOG.log" />
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="fileNamePattern" value="logs/OTHER_LOG.%d{yyyyMMddHHmmss}.%i.log" />
</rollingPolicy>
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="maxFileSize" value="1000000" />
</triggeringPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="..." />
</layout>
</appender>
<category name="com.main.log4j.other" additivity="false">
<appender-ref ref="OTHER-LOG" />
</category>
<root>
<level value="debug" />
<appender-ref ref="CONSOLE-LOG" />
</root>
I have tried with log4j version - 1.2.16,1.2.17; Still getting the warning and my purpose is not fulfilled.
Please let me know where I have done the mistake.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…