Reputation:
How to write logs in text file but do not overwrite the file?
Logger logger = Logger.getLogger("MyLog");
FileHandler fh = new FileHandler("C:/temp/test/MyLogFile.log");
logger.addHandler(fh);
...
logger.info("log sample");
Upvotes: 1
Views: 2312
Reputation: 2891
Change this :
FileHandler fh = new FileHandler("C:/temp/test/MyLogFile.log");
to this
FileHandler fh = new FileHandler("C:/temp/test/MyLogFile.log", true);
If you read the documentation you will see that the second argument specifies the optional append argument. When true you will write at the end of the (existing) file, without overwriting it.
See documentation
Upvotes: 4