log4j:ERROR Failed to rename
Asked Answered
U

2

8

I get this error "log4j:ERROR Failed to rename" in my tomcat server log. I have multiple DailyRollingFileAppender in my log4j XML. And each appender points to different file. Only once instance of the application is running. I used Handle utility and run the command (with log file name as parameter)

handle -f ams-app.log and the result is Tomcat7.exe pid: 5032 type: File 54C: E:\apps\ams\logs\ams-app.log

From this I assume there is only one lock on the file. My environment Windows Server 2008, tomcat 7.0 and Java 6 and slf4j-log4j12(1.5.6)

This problem was not happening when same application hosted on AIX server. I googled this problem and it seems to be windows specfic. Also I am not keen to use DatedFileAppenders or any forked log4j. Does logback solve such issues. Any suggestions on how to solve this problem is appreciated. Thanks

here my log4j xml

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CONSOLE_APPENDER" class="org.apache.log4j.ConsoleAppender">
    <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
    <param name="Target" value="System.out"/>
    <param name="Threshold" value="DEBUG"/>
    <layout class="org.apache.log4j.PatternLayout">     
        <param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m  %n"/>
    </layout>
</appender>

<appender name="APP_APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
    <param name="datePattern" value="yyyy-MM-dd"/>
    <param name="file" value="E:/apps/ams/logs/ams-app.log"/>
    <param name="append" value="true"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m  %n"/>
    </layout>        
</appender>

<appender name="SQL_APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
    <param name="datePattern" value="yyyy-MM-dd"/>
    <param name="file" value="E:/apps/ams/logs/ams-sql.log"/>
    <param name="append" value="true"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m  %n"/>
    </layout>
</appender>

<appender name="Quartz_APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
    <param name="datePattern" value="yyyy-MM-dd"/>
    <param name="file" value="E:/apps/ams/logs/ams-Quartz.log"/>
    <param name="append" value="true"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%n %d{yyyy/MM/dd HH:mm:ss} %-5p %x %M(%F:%L) - %m  %n"/>
    </layout>
</appender>


<logger name="org.springframework"><level value="WARN"/></logger>
<logger name="flex.messaging.log.ServletLogTarget"><level value="WARN" /></logger>
<logger name="net.sf.jasperreports"><level value="WARN" /></logger>
<logger name="net.sf.jasperreports.engine.fill"><level value="WARN" /></logger> 
<logger name="org.apache.commons.beanutils"><level value="WARN" /></logger>
<logger name="jdbc.sqltiming" additivity="false"><level value="DEBUG"/><appender-ref ref="SQL_APPENDER"/></logger>
<logger name="org.quartz" additivity="false"><level value="WARN" /><appender-ref ref="Quartz_APPENDER"/></logger>
<logger name="org.quartz.SchedulerException"><level value="ERROR" /><appender-ref ref="MAIL_APPENDER"/></logger>     
<logger name="org.hmil.ams.BatchDAO" additivity="false"><level value="INFO"/><appender-ref ref="Quartz_APPENDER"/></logger>
<root>      
    <priority value="debug"></priority> 
    <appender-ref ref="APP_APPENDER" />      
    <appender-ref ref="CONSOLE_APPENDER"/>
</root>

Unwilled answered 16/11, 2012 at 4:1 Comment(1)
Can you pls post the log4j configuration ?Coal
T
3

It appears that if you're running windows this is a known bug:

see here: http://do.whileloop.org/2014/02/14/log4j-rolling-file-appenders-in-windows/

See here: https://issues.apache.org/bugzilla/show_bug.cgi?id=29726

And also here: http://www.coderanch.com/t/424837/java/java/Log-log-file-rolled-day

Thimerosal answered 26/9, 2014 at 19:44 Comment(0)
E
0

I had the same issue and fixed it by updating log4j to version 1.2.15 as per this discussion

Extinguish answered 8/10, 2013 at 16:26 Comment(2)
We use log4j 1.2.15 but we have same problem still with that version.Zerelda
I found the solution to my problem and wanted to share here. When adding appender-ref in logger tag, it throws renaming error. When adding appender-ref in root tag, it never throws that error.Zerelda

© 2022 - 2024 — McMap. All rights reserved.