You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "hpcnx (via GitHub)" <gi...@apache.org> on 2024/02/07 16:10:31 UTC

[I] Log4j2 force rollover does not create empty backup *.log.1 file like logj4 (logging-log4j2)

hpcnx opened a new issue, #2272:
URL: https://github.com/apache/logging-log4j2/issues/2272

   ## Description
   Log4j2 RollingFileAppender rollover() function does not create new rollover file on empty log.
   
   [A clear and concise description of what the bug is.]
   Using RollingFile appender and with SizeBasedTriggeringPolicy. And on top of it, we do flush the log by calling RollingFileAppender's myappender.getManager().rollover(); on demand.
   When we using older log4j, the behavior was even the current log is empty, for example, myrecord.log (0 size), it will create new myrecord.log.1 (0 size). 
   But with new log4j2, there is no myrecord.log.1 is created. 
   
   Another example, initial log has content inside, 
   myrecord.log (not empty)
   When force rollover(),
   It creates myrecord.log.1 (same content as original myrecord.log), and new myrecord.log is empty.
   Do another flush (calling rollover()), and we expect myrecord.log (empty), myrecord.log.1(empty) and myrecord.log.2 (with content) just like it was in log4j.
   But the new behavior now is only myrecord.log (empty) and myrecord.log.2 (with content).
   The file myrecord.log.1 (empty) is missing
   
   
   ## Configuration
   <RollingFile
   		  name="MyRecord"
   		  fileName="${LOG_BASEPATH}/myrecord.log"
   		  filePattern="${LOG_BASEPATH}/myrecord.log.%i"
   		  ignoreExceptions="false">
   			<PatternLayout>
   				<Pattern>${LOG_PATTERN}</Pattern>
   			</PatternLayout>
   			<Policies>
   				<SizeBasedTriggeringPolicy size="10 MB" />
   			</Policies>
   			<DefaultRolloverStrategy max="5" fileIndex="min" />
   		</RollingFile>
   		
   **Version:** [Log4j version]
   <log4j2.version>2.21.1</log4j2.version>
   
   **Operating system:** [OS and version]
   Windows Server 64bits
   
   **JDK:** [JDK distribution and version]
   Java8 and Java21
   
   ## Logs
   No error log, it is the rollover() output behavior changed from log4j
   ```
   [Stacktraces, errors, etc. relevant applications logs.]
   ```
   
   ## Reproduction
   Calling rollover() from RollingFileAppender rfa = ..;
   rfa.getManager().rollover();
   And check the output rollover log files.
   
   [An isolated test reproducing the test.
   JUnit tests similar to the ones in the code base are extremely appreciated.]
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Log4j2 force rollover does not create empty backup *.log.1 file like logj4 (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #2272:
URL: https://github.com/apache/logging-log4j2/issues/2272#issuecomment-1934833851

   The `RollingFileManager` has a `renameEmptyFiles` property that decides whether or not to rename empty files.
   
   It is an internal property and usually triggering policies manage its value. If you force the rollover programmatically, you can call:
   
   ```java
   RollingFileManager rf = ...;
   rfm.setRenameEmptyFiles();
   rfm.rollover();
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Log4j2 force rollover does not create empty backup *.log.1 file like logj4 (logging-log4j2)

Posted by "hpcnx (via GitHub)" <gi...@apache.org>.
hpcnx closed issue #2272: Log4j2 force rollover does not create empty backup *.log.1 file like logj4
URL: https://github.com/apache/logging-log4j2/issues/2272


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Log4j2 force rollover does not create empty backup *.log.1 file like logj4 (logging-log4j2)

Posted by "hpcnx (via GitHub)" <gi...@apache.org>.
hpcnx commented on issue #2272:
URL: https://github.com/apache/logging-log4j2/issues/2272#issuecomment-1939121723

   With setRenameEmptyFiles(true); the empty log file is rollover like log4j API. 
   Thanks a lot! 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Log4j2 force rollover does not create empty backup *.log.1 file like logj4 (logging-log4j2)

Posted by "hpcnx (via GitHub)" <gi...@apache.org>.
hpcnx commented on issue #2272:
URL: https://github.com/apache/logging-log4j2/issues/2272#issuecomment-1939130695

   Maybe keep the default rollover() behavior in log4j2 the same as it was in log4j, or document the default behavior change between log4j2 vs. log4j would be also help on this, right?
   Thanks again!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org