I am trying to use a RollingFileAppender with a CompositeTriggeringPolicy that includes a OnStartupTriggeringPolicy which is deemed to rollover the log when the JVM is (re-)started.
However, I have noted that the files only roll over on startup when I specify "minsize = 0" on the log4j2.xml configuration file. If I put any other value or leave the minsize unspecified (i.e. rely on its default value minsize = 1), the appender proceeds writing to the previously existing file.
I have run the debugger and traced down the bug according as follows.
All the logic in OnStartupTriggeringPolicy.initialize() is conditioned upon the size of the rolling file being larger than minSize
However, manager.getFileSize() always returns 0, thus the body of that if is never entered (... unless minSize == 0). In fact, this call to OnStartupTriggeringPolicy.initialize() is invoked indeed from RollingFileManager.initialize() before any value has been assigned to size
Thus, within OnStartupTriggeringPolicy.initialize(), manager.getFileSize() always evaluates to 0, and the only way that the file is rolled over at startup is that minSize has been configured as 0.
As a side consequence, this may also affect SizeBaseTriggerinPolicy if a rollover is needed by coincidence during startup.