Bug 900 - RollingFileAppender does not work properly under Windows NT
Summary: RollingFileAppender does not work properly under Windows NT
Status: RESOLVED DUPLICATE of bug 29726
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: unspecified
Hardware: PC All
: P1 critical
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
: 5211 (view as bug list)
Depends on:
Blocks:
 
Reported: 2001-03-08 04:47 UTC by ras
Modified: 2005-03-07 11:08 UTC (History)
3 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ras 2001-03-08 04:47:22 UTC
We use the RollingFileAppender under Windows NT and simultaneously open the log 
file in a log viewer.
Under these conditions, the appender no longer works because renaming a file 
that has been opened is not permitted, possibly resulting in a loss of data.
There are not any problems under linux.
We have found a way of solving this and use this derived appender.
It is based on the idea that a rollover does not take place in case the file 
has been opened by a second application.
This is tested through a renameTo using the original file name.We use the 
RollingFileAppender under Windows NT and simultaneously open the log file in a 
log viewer.
Under these conditions, the appender no longer works because renaming a file 
that has been opened is not permitted, possibly resulting in a loss of data.
There are not any problems under linux.
We have found a way of solving this and use this derived appender.
It is based on the idea that a rollover does not take place in case the file 
has been opened by a second application.
This is tested through a renameTo using the original file name.

Our derived appender class:

package org.apache.log4j;

import java.io.File;
import java.io.IOException;


public class RollingFileAppenderEx extends RollingFileAppender 
{
  public
  RollingFileAppenderEx() 
  {
  	super();
  }
  
  public
  synchronized
  boolean canRename()
  {
  	boolean bRet = false;
  	File file;
	try 
	{	
		file = new File(fileName);
		this.closeFile();
		bRet = file.renameTo(file);
		this.setFile(fileName, true);
	}
	catch(IOException e){}
	return bRet;
  }
  
  public
  synchronized
  void rollOver() 
  {
  	if (canRename() == true)
	{
		super.rollOver();
	}		
  }
}
Comment 1 Brian Thorstad 2004-02-16 15:59:11 UTC
We have a related problem in that we have multiple output specifications all 
logging to the same file.  We do this to have the layoutPattern distinct for 
different major subsystems.  In this case, however, the RollingFileAppender 
does not "roll".

IMO, ideal behavior would be for rolling behavior (for output specs to the same 
file) to be in place, with the caveat that if the various output specs 
specified different parameters for the rolling, which is selected is non-
deterministic.
Comment 2 Ceki Gulcu 2004-05-28 17:38:40 UTC
*** Bug 5211 has been marked as a duplicate of this bug. ***
Comment 3 Mike O'Keefe 2005-03-07 20:08:45 UTC

*** This bug has been marked as a duplicate of 29726 ***