Laurent,

We solved the problem with the following code.  We extended the Log4J
RollingFilleAppender and overrode the rollover() method.  All calls to
file.renameTo() were replaced with calls to our own rename method.  This
tries to do a normal file.renameTo, but if it fails it does a manual copy.
I can't say this is a solution to be proud of, but it works.

The environment is AIX 4.3, JRE 1.1.8.  I can't recall the full detials, I
don't know if we reproduced in on Windows or not and we couldn;t explain why
the original code fails.  We are running in an application server, so
multiple threads are all calling the logger.

We couldn't find anybody else experiencing the same problem when we looked
at it 9 months ago.
Here's the code anyway.  Give it a try, you could always add a println to
see if renameTo() ever returns false.
Does anybody else have any comments?

Tim.


/**
* Rename file. If fails, copy it.
*
* @param src The source file
* @param target The target file
*/
private static void renameFile(File src, File target) {
    if (!src.renameTo(target)) {
        try {
            copyFile(src, target);
        } catch (IOException e) {
            System.out.println("Can't rename file 'cause " +
e.getMessage());
        }
    }
}

/**
* Copy a file to another file
*
* @param source The source file
* @param target The target file
* @exception IOException
*/
private static void copyFile(File source, File target) throws IOException {
    char c = '\u0400';
    byte abyte0[] = new byte[c];
    FileInputStream fileinputstream = new FileInputStream(source);
    BufferedInputStream bufferedinputstream
        = new BufferedInputStream(fileinputstream);
    FileOutputStream fileoutputstream = new FileOutputStream(target);
    BufferedOutputStream bufferedoutputstream
        = new BufferedOutputStream(fileoutputstream);
    int i;
    while((i = fileinputstream.read(abyte0)) != -1) {
        fileoutputstream.write(abyte0, 0, i);
    }
    bufferedoutputstream.close();
    bufferedinputstream.close();
}


----- Original Message ----- 
From: "Laurent Blume" <[EMAIL PROTECTED]>
To: "Log4J Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, October 28, 2003 6:27 AM
Subject: Re: log4j losing log files


> Tim Williams wrote:
>
> > I just joined the list so I missed the original post.
> > Is this about Log4J not rolling over files properly with the
> > RollingFileAppender?
>
> Yep!
>
> > We ended up writing a modified version because for some reason it held
locks
> > and wouldn't 'rollover' properly, so we lost the log files.
>
> Sounds like what I'm experiencing. I attached my original post, I hope
> this list will allow it.
>
> > Let me know if this is what you are experiencing and I'll dig out the
code.
> > Also, what operating system are you running on?
>
> It's a Windows 2000 box, I think reasonably up-to-date.
>
> I'm going to try Yoav's advice right now, and I'll come back to the list
> with some fresh (and hopefully helpful) debug output!
>
> Laurent
>



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

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

Reply via email to