Bug 43879 - FileAppender writes Header multiple times
Summary: FileAppender writes Header multiple times
Status: NEEDINFO
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.3alpha
Hardware: Other other
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-16 02:40 UTC by Martin Maier
Modified: 2007-11-16 05:54 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Maier 2007-11-16 02:40:18 UTC
FileAppender writes the Header again when an existing LogFile exists.
FileAppender should write the header only once per file (functionality not
documented). If so, the method writeHeader should check whether the file is
empty before writing a new header. If the file already contains data, no header
should be written. Otherwise you could end up having multiple headers in your
file (if you restart your JVM several times for instance).

A fix could look like this:

protected void writeHeader() {
	File logFile = new File(getFile());
	if (layout != null && this.qw != null && logFile.length() == 0) {
		this.qw.write("my Header\n");
	}
}
Comment 1 Ram "Mrm" Mohan 2007-11-16 05:54:36 UTC
http://logging.apache.org/log4j/1.3/index.html mentions log4j users should
upgrade to the latest v2

Does this fix really need to take place in v1.3 since it looks like you already
have a workaround for your current version?