Aly
Aly

Reputation: 16255

adding date to Java util logger fileHandler name

Hi I currently have this in my .properties file:

java.util.logging.FileHandler.pattern = %h/programName%u%g.log

I would also like to append a timestamp / username to this so its easy to identify log files does anyone know how?

Upvotes: 2

Views: 6398

Answers (1)

shoover
shoover

Reputation: 3130

Since the FileHandler methods don't have a % substitution variable for date, my suggestion would be to format a string that includes the date before passing the string to FileHandler. Something like:

String pattern = String.format("%%h/programName%tYmd%%u%%g.log", today);
FileHandler fh = new FileHandler(pattern);

Upvotes: 3

Related Questions