Log4J: crash on re-closing after closing using TimeBasedRollingPolicy

I have a TimeBasedRollingPolicy setting to deploy a file every minute (for testing purposes), and the problem I am facing is a warning and a zip or gz file is not created. Warning:

log4j: WARN Failure to close again after closing

I have attached the source to the clarification of the problem, but have not yet succeeded. Am I missing any configuration in my log4j.xml?

<appender name="errorAppender" class="org.apache.log4j.rolling.RollingFileAppender"> <param name="File" value="C:/error.log"/> <param name="Append" value="true"/> <param name="BufferedIO" value="true"/> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> <param name="FileNamePattern" value="C:/error.%d{ddMMMyyyy HH:mm:ss}.log.gz" /> <param name="ActiveFileName" value="C:/error.log"/> </rollingPolicy> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %C (line:%L) - %m%n"/> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMax" value="error"/> <param name="LevelMin" value="error"/> <param name="AcceptOnMatch" value="true"/> </filter> </appender> 

I am using log4j-1.2.17 and apache-log4j-extras-1.1. Has anyone seen this problem or had any idea about it?

+4
source share
6 answers

The problem with the log4j: WARN Failure in post-close rollover action message is that on Windows-based systems you cannot create a file name using the ":" char, so the specified FileNamePattern must not contain any of the following: \, / ,:, *,?, ", <,>, |

Here it is log4j.xml for my application that works fine with the copied file. For testing purposes, I did a casting to create a new file every second:

 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="consola" class="org.apache.log4j.ConsoleAppender"> <param name="target" value="System.out"/> <layout class="org.apache.log4j.PatternLayout"> <param name="conversionPattern" value="[%d{yyyyMMdd HH:mm:ss:mm,SSS}]%-5p [%t] [%c{1}-%M:%L] - %m%n"/> </layout> </appender> <appender name="desarr" class="org.apache.log4j.rolling.RollingFileAppender"> <param name="Append" value="false"/> <rollingPolicy name="desarr" class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> <param name="fileNamePattern" value="C:/workspace/Probador/log/backups/importacion222.log_%d{mmss_mm}"/> <param name="activeFileName" value="C:/workspace/Probador/log/importacion222.log"/> </rollingPolicy> <layout class="org.apache.log4j.PatternLayout"> <param name="conversionPattern" value="[%d{yyyyMMdd HH:mm:ss:mm,SSS}]%-5p [%t] [%c{1}-%M] - %m%n"/> </layout> </appender> <root> <priority value ="debug" /> <appender-ref ref="consola" /> <appender-ref ref="desarr"/> </root> </log4j:configuration> 

Special attention:

 <param name="fileNamePattern" value="C:/workspace/Probador/log/backups/importacion222.log_%d{mmss_mm}"/> 

Try this before trying to archive the file.

+4
source

I encountered the same problem in log4j with the WARN message - "log4j: WARN Failure in post-close rollover action", and the log file did not flip. At the root there was a problem with insufficient resolution in the directory in which the log file was written. In this case, the Java method File.renameTo () failed (it simply returns a boolean false). It took a long time to figure out the problem :(

+2
source

I am using log4j-1.2.17 and apache-log4j-extras-1.1. Has anyone seen this problem and have any information about it?

I also observed this problem using log4j-1.2. 16 and apache-log4j-extras-1.1. The exact message.

I tried various settings to no avail. The only time that rollPolicy-> FileNamePattern is observed when it is used without the appender-> File parameter and the rollPolicy-> ActiveFileName parameter. But even so far I have not seen it topple over successfully, and not the gz or zip of previous files.

I also get the same messages:

 log4j: setFile called: somepath/somefile.log, true log4j: setFile ended log4j:WARN Failure in post-close rollover action 

Very frustrating.

+1
source

I also had the same problem, but in my case it was because the path folder fileNamePattern did not exist. Then patches were created that worked for me and rollover files.

0
source

For me, the solution was to manually create a directory for the archive files.

0
source

If you use the org.apache.log4j.rolling.TimeBasedRollingPolicy directories, then the directory must exist before log4j can rotate.

For example, the following poll will only work if the directory / var / log / blah / archive / YYYY / MM exists; To create it in the night crown should do the trick. And, as mentioned earlier, this will also happen when there is not enough permission to create a log file.

  <appender name="infoFile" class="org.apache.log4j.rolling.RollingFileAppender"> <param name="threshold" value="INFO"/> <param name="append" value="true"/> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> <param name="ActiveFileName" value="/var/log/blah/file.log"/> <!-- IMPORTANT the archive folder must already exist, or log4j cannot put the rotated log there, and will keep using the old one --> <param name="FileNamePattern" value="/var/log/blah/archive/%d{yyyy}/%d{MM}/file.log.%d{yyyy-MM-dd}.gz"/> </rollingPolicy> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%5p | %-40c{2} | %-4L | %d{yyyy-MM-dd}T%d{HH:mm:ss} | %m%n"/> </layout> </appender> 
0
source

All Articles