Alex Rivera | Logout

How do I overwrite a log file in log4j?

Asked 2009-06-08T15:52:48.203
22

I have a log file that has the following appender added to it :


logger.addAppender(new FileAppender(new PatternLayout(),"log.txt"));

the thing is, each time I'm running my application, additional logging information gets appended to the same log file. What can I do to overwrite the file each time ?

Edit
Report

1 Answer

6

The previous answer by Matt is correct except that it uses a properties file. If you are looking for a programmatic approach, I suggest that you disable append mode by modify your code as follows:

logger.addAppender(new FileAppender(new PatternLayout(),"log.txt", **false**));
answered 2009-06-09T09:28:32.917

Your Answer