I saw Java Logging - where is my log file?, but in my case I would like to find out in my Java application which logfile the FileHandler
actually opened, i.e. if I start multiple processes and have a pattern set as
java.util.logging.FileHandler.pattern=MyApp.%g.%u.log
Then the %g
and %u
will be replaced with numbers depending on how many processes are running.
I can iterate over all logging Handlers and find the File-based one. But as far as I see there is no method in FileHandler
to get the currently opened file.
Is there a way I can do this?
Yes, you can break the
private
protection of the field using reflection. See this question: How do I read a private field in Java?The next option is to override the class and write your own handler which exposes this field.
The last option is to use a different logging framework like logback or log4j2. Writing your own appender for them would be more simple than for JUL.