0

I understand how the Java FileHandler rolls to the next log file when a particular size is reached. What I want is a little different. I want to use the FileHandler to use the log file with the oldest last written time in the sequence when the program starts.

For example if I have specified to use 5 log files: mylog.0.log, mylog.1.log...mylog.4.log

If the program last updated mylog.2.log then the next time I start the program I want it to start logging to mylog.3.log.

The problem I am trying to solve is when a user executes the program and something happens they typically restart the program and if mylog.0.log is available it will always use it and not go to mylog.1.log. I lose the information from the previous execution of the program.

Brian McCormick
  • 449
  • 4
  • 5

1 Answers1

1

Per the documentation for the java.util.logging.FileHandler:

Successively older files are named by adding "0", "1", "2", etc. into the base filename.

Seems to imply that the order will always be the opposite of what you want.

Looks like your only option is to implement a config class to generate the file name you want and pass it to the FileHandler.

You can manually rollover a log file but not in the order your want.

Community
  • 1
  • 1
jmehrens
  • 10,580
  • 1
  • 38
  • 47
  • Wouldn't setting the limit to 1 just write 1 byte to the file before rolling to the next one? How does this solve my issue. I want to write everything to a single log file for the lifespan of the program and then use the next sequenced logfile for the next invocation of the program etc. and then roll back to logfile 0 when it get to the max number of logfiles I want to use. – Brian McCormick Sep 02 '16 at 15:10