I use java.util.logging and have multiple war apps in glassfish servers. I'd like JUL to log to a different file for each war (currently glassfish logs everything to server.log). I know this is easy to do with log4j or other logging modules, but I'd like to stick to JUL. (Would not like to discuss if JUL is my best option). Is it possible? Thanks
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It is possible to append a different FileHandler to a Logger.
If you have a normal logger:
private final static Logger LOGGER = Logger.getLogger(Something.class.getName());
Add a new FileHandler:
Handler fh = new FileHandler("/home/file.log");
LOGGER.addHandler(fh);
Log statements will be written to the file in some XML format...