Hi,

I tested a log4j configuration where I have 2 DailyRollingFileAppender pointing 
to the same physical file and having a different PatternLayout. The first one 
is used by the root logger and the second one by an explicit logger.

In my previous post, I used this configuration on a Oracle JVM, now on a 
standard Sun JVM.

In both cases, when it's time to rollover the file, the renaming fails.

The reason is that each appender maintains a handle on the file resulting in 
two handles, that creates a lock and the renaming always fails and the previous 
log content is lost.

-----------------------------------------------------
Handle v2.2
Copyright (C) 1997-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

java.exe           pid: 1876   C:\transferService.log
java.exe           pid: 1876   C:\transferService.log
-----------------------------------------------------

I wonder whether it is the correct behavior ? It seems to me that log4j has a 
full control on its configuration and could handle this situation. Maybe this 
could be fixed in version 1.3 ?

Adriano Labate


-----Message d'origine-----
De : Adriano Labate [mailto:[EMAIL PROTECTED] 
Envoy� : mercredi, 1 d�cembre 2004 17:06
� : [EMAIL PROTECTED]
Objet : Multiple DailyRollingFileAppender on the same file : renaming fails

Hi,

I just resolved a problem with the DailyRollingFileAppender and I just want to 
share my experience with others. If it can help someone...

When it was time to rollover the file, I got the error:

"log4j:ERROR Failed to rename [c:/temp/mspak/monitoring/transferService.log] to 
[c:/temp/mspak/monitoring/transferService.log.2004-11-25.log]."

I search on Google for this error and found around 200 results and realized 
that it was a problem for a lot of people.

As I use log4j with the Oracle JVM I supposed that it was an Oracle issue with 
I/O or permissions. After a lot of discussions with the Oracle support, it was 
definitely not the case.

I noted that a lot of discussions talked about the possibility that the file 
has a handle on it that prevents log4j to rename the file.

To be sure I installed and run 2 tools from www.sysinternals.com : Handle and 
Process Explorer.

Running Handle I got :

--------------
C:\>handle -u transferservice.log
Handle v2.2
Copyright (C) 1997-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

oracle.exe         pid: 984    AUTORITE NT\SYSTEM        
C:\TEMP\MSPAK\monitoring\transferService.log
oracle.exe         pid: 984    AUTORITE NT\SYSTEM        
C:\TEMP\MSPAK\monitoring\transferService.log
--------------

There was indeed two handles on my log file. I double checked with Process 
Explorer (a GUI app) and confirmed that Oracle maintained two handles on my log 
file. Now I was sure that it was a file handle problem.

Then I got a flash and realized that in my log4j.xml configuration file I have 
two daily rolling file appenders that pointed on the same physical file.

I tried to keep only one of them. Retried and YES, there was now only one 
handle on the file!
Tested the rollover and it finally worked!


My configuration file was :

--------------
    <!-- Daily Rolling File Appender -->
    <appender name="DRFA" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="Threshold" value="DEBUG"/>
        <param name="File" 
value="c:/temp/mspak/monitoring/transferService.log"/>
        <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{dd.MM HH:mm:ss:SSS} %-5p 
[%c] %m%n"/>
        </layout>
    </appender>

    <!-- Daily Rolling File Appender   WARNING: disabled because file renaming 
fails!!!
    <appender name="DRFA-blankpattern" 
class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" 
value="c:/temp/mspak/monitoring/transferService.log"/>
        <param name="DatePattern" value="'.'yyyy-MM-dd'.log'"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%m%n"/>
        </layout>
    </appender>
    -->
--------------

I have now a question: 

I didn't tried to use that configuration outside of Oracle, is it wrong to use 
2 appenders pointing on the same file (windows xp) ? 
I searched on the G�lc� log4j manual but didn't found anything. Has anyone 
tried to use this kind of configuration ?

I know that the Oracle JVM handles the threading differently than the Sun JVM, 
so it can also explain the problem.

Adriano Labate




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to