0

We have recently migrated log4j2-beta9 to log4j2-2.0 version. We are facing an issue with the roll over file.

The first issue: The roll over file does not zip and only .log file remains.

The second issue: The active file does not get cleared. The logs keep getting added to the same file, hence increasing the file size.

Please find my log4j2.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j2config [
<!ENTITY appenders SYSTEM "#USER_INSTALL_DIR#/wwf/config/properties/log4j2-appenders.xml">
<!ENTITY loggers SYSTEM "#USER_INSTALL_DIR#/wwf/config/properties/log4j2-loggers.xml">
]>
<configuration monitorInterval="30" status="debug">
  <properties>
    <property name="log4j2.logDir">.</property>
    <property name="logDir">${sys:log4j2.logDir}</property>
    <property name="log4j2.filePrefix">default</property>
    <property name="filePrefix">${sys:log4j2.filePrefix}</property>
  </properties>
  <appenders>
    <RollingFile name="Default" fileName="${logDir}/${filePrefix}.log"
                 filePattern="${logDir}/${filePrefix}/${filePrefix}-%d{MM-dd-yyyy}-%i.log.gz">
      <PatternLayout charset="UTF-8" pattern="%d %-5p [%t] %c %m [%M:%L %X] %n"/>
      <Policies>
        <SizeBasedTriggeringPolicy size="1 MB"/>
      </Policies>
      <DefaultRolloverStrategy max="200"/>
    </RollingFile>
    <Console name="Console" target="SYSTEM_ERR">
        <PatternLayout charset="UTF-8" pattern="%d %-5p [%t] %c %m [%M:%L %X] %n"/>
    </Console>
    &appenders;
  </appenders>
  <loggers>
    <logger name="SYSTEM_OUT" level="info" additivity="false">
        <appender-ref ref="Default" />
        <appender-ref ref="Console" />
    </logger>
    <logger name="SYSTEM_ERR" level="error" additivity="false">
        <appender-ref ref="Default" />
        <appender-ref ref="Console" />
    </logger>
    <logger name="com.abc" level="debug" additivity="false">
      <appender-ref ref="Default"/>
    </logger>
    <logger name="com.xyz" level="debug" additivity="false">
      <appender-ref ref="Default"/>
    </logger>
    <logger name="com.abcdef" level="debug" additivity="false">
      <appender-ref ref="Default"/>
    </logger>
    <logger name="com.abcdef.commons" level="debug" additivity="false">
        <appender-ref ref="Default"/>
    </logger>
    <logger name="org.springframework" level="warn" additivity="false">
      <appender-ref ref="Default"/>
    </logger>
    <root level="error">
      <appender-ref ref="Console"/>
    </root>
    &loggers;
  </loggers>

</configuration>
Shashi
  • 339
  • 1
  • 4
  • 15

2 Answers2

1

The issue occurs because node 1 in cluster setup is behaving as the admin server also. But the JVM for admin server and node 1 is different. Both these JVMs are using the same file appserver.log for logging. However, admin server will not add anything to the log file. Nevertheless, it is still locking the appserver.log. Thus, the appserver.log is not getting cleared.

Hence in your setup, check if appserver.log is being locked for some reason.

In our case, we fixed the issue by creating a dummy appserver.log for the admin server. This way our log file is not locked.

Shashi
  • 339
  • 1
  • 4
  • 15
0

Have you tried adding <TimeBasedTriggeringPolicy /> to your <RollingFile>...<Policies> section? You currently only have a size based triggering policy but your filePattern has a date.

Also, your config has a strange string &appenders; - you should probably remove this.

    </Console>
    &appenders;
  </appenders>

Similar for loggers:

    </root>
    &loggers;
  </loggers>
Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • Couple of updates on the above issue: We are not facing the issue when we have a stand alone setup. This issue arises when we have a cluster setup. In the cluster setup, the admin server and one of the nodes is the same. In such a scenario, we are getting the log file rollover issue. The other node, however, works fine. The logs are rolling and zipping. Also the current file is getting emptied. I am really struggling to find the root cause of the issue. I tried both the things suggested, but they did not help! – Shashi Sep 15 '14 at 11:03
  • Does that mean you have two processes writing to the same file? – Remko Popma Sep 15 '14 at 11:57
  • No, the admin server is only for load balancing. It does not have any process writing to the log file. – Shashi Sep 15 '14 at 12:22
  • One more thing that I observed is that while copying the file, it always renames the new file as: 2014-09-15 11:13:13,782 DEBUG RollingFileManager executing synchronous FileRenameAction[D:\version1\cluster1\ap1\config\logs\appserver.log to D:\version1\cluster1\app1\config\logs\appserver\appserver-09-15-2014-1.log, renameEmptyFiles=false]. It is always 1. The number does not increment. The current file is copied and suffixed with date and -1.log – Shashi Sep 15 '14 at 12:24
  • The suffix is only increased if the size-based trigger kicks in before the date-based trigger. So if you rollover every day, and you have a size trigger of 10MB, you should get a number of 10MB files with increasing index for each day. – Remko Popma Sep 15 '14 at 12:47
  • That is what is happening for us. The size reaches 10MB within 1 day, so we expect that there should be files something like these created: appserver-09-16-2014-1.log, appserver-09-16-2014-2.log. But it always creates appserver-09-16-2014-1.log. – Shashi Sep 16 '14 at 10:10
  • Hmm... Would you mind raising a ticket for this on the log4j2 Jira issue tracker so the rest of the team can look at it also? Thanks! – Remko Popma Sep 16 '14 at 12:29