Multiple apps in glassfish JUL logging to differen

2019-06-07 17:19发布

问题:

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...