Search code examples
javaloggingdesign-patternsfilehandler

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?


Solution

  • 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);