views:

54

answers:

1

I have the below configured for log4j which outputs a csv log file. Every time my program executes I wish to start this log file a fresh by overwriting not appending to the log file. I thought I could achieve this by using the append=false. I know that I have correctly set up log4j as other logs are outputting fine but these are daily rolling logs that are appending which is the desire affect.

Can anyone tell me why the append=false doesn't seem to work. Is there another setting I've missed?

Here's my config code:

#Image output
log4j.logger.fetch.FetchDirectHolidays=debug, S
log4j.appender.S=org.apache.log4j.FileAppender
log4j.appender.S.File=xml\\logs\\FetchDirectHolidays.csv
log4j.appender.S.append=false 
# Keep one backup file
log4j.appender.S.layout=org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern= %p , %m%n

What is wrong with my configuration?

I forgot to state that my application is scheduled and I have just read that the Append=false only clears the log file if the whole application is shutdown and restarted. This does not help as I need to clear this log file each time the internal processes executes.

A: 

Try

log4j.appender.S.Append=false

with a capital A for Append

crowne
Tried this but it doesn't work. I found that the Append=false only works when you shutdown the application altogether. I can not do this as mine is scheduled. Hoeve
Andrew Harrison
However, I have found that I should be able to shutdown the logger by using LogManager.shutdown() and then delete the log file. Not the best but it should work.
Andrew Harrison
You could try writing your own appender, modelled/extending FileAppender. Let your appender keep track of the last thread id, and when it changes then re-open the file. Assuming your scheduled unit of work executes completely in a single thread.
crowne
Thank you for the advice seems like the best solution so far :-) I give it a go.
Andrew Harrison