Find actual opened logfile with JDK Logging

女生的网名这么多〃 提交于 2020-01-17 08:31:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30707522/find-actual-opened-logfile-with-jdk-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!