0
votes

The Rolling File Appender is not putting the most recent log entries in the current date file.

In the log4j2.xml file I have a RollingFile appender which looks like this

    <RollingFile
    name="viewAppender"
    filePattern="/data/view/view%d{yyyy-MM-dd}.log">

    <PatternLayout><pattern>%m%n</pattern></PatternLayout>

    <Policies>
      <TimeBasedTriggeringPolicy />
  </Policies>
</RollingFile>

When the new log entry goes, its not going in the current date Here is the log file. It shows that the most recent entry was from Aug 30 but the log file name was for Aug 28. It should have created a new log file with filePattern view2018-08-30.log

-rw-r--r--    1 root     root           230 Aug 30 10:36 view2018-08-28.log
1
I'm not able to recreate your issue with the information provided. Please provide a Minimal, Complete, and Verifiable ExampleD.B.

1 Answers

0
votes

You can use below log4j2.xml which is a working one and creates new log file everyday

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60">
<Appenders>
<Console name="console-appender" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - 
 %msg%n"/>
</Console>
<RollingFile name="rollingFile-appender"
  fileName="${sys:user.home}/log/apache-tomcat/file.log"
  filePattern="${sys:user.home}/log/apache-tomcat/file-%d{yyyy-MM-dd}.log">
  <PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - 
   %msg%n"/>
<Policies>
  <TimeBasedTriggeringPolicy/>
  <SizeBasedTriggeringPolicy size="50MB"/>
  </Policies>
  <DefaultRolloverStrategy max="30"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="info">
  <AppenderRef ref="rollingFile-appender"/>
  <AppenderRef ref="console-appender"/>
</Root>
</Loggers>
</Configuration>