Logging app messages into another file than server.log
Hello:
I'm working with Application Server Enterprise Edition 7 2004Q2 and I'd like logging application messages into another file than server.log.
I tried to set up a logging configuration file as
com.appname.handlers = java.util.logging.FileHandler
( where all packages in my application are named like com.appname.* )
and pass it as
-Djava.util.logging.config.file
But nothing happens. Indeed , no file is created.
I tried with
handlers = java.util.logging.FileHandler
and works fine but, obviusly, are wrote server messages too.
So, the problem is 'com.appname.handlers ' property, but I dont know why.
any workaround to perform this ?
what's wrong ?
Thanks in advance.
Best regards
[788 byte] By [
Grohl] at [2007-11-26 11:36:02]

# 3
Hi,
The samples are usaully in the samples directory of the appserver install dir. However, this might depend on the server install.
Anyway, samples can be downloaded from:
http://developers.sun.com/prodtech/appserver/reference/codesamples/index.html
This is a zip file with all the samples stuff
The actual code in there:
// import for logging classes
import java.util.logging.*;
//Remove all handlers
Handler[] h = logger.getHandlers();
for (int i = 0; i < h.length; i++) {
logger.removeHandler(h[i]);
}
//Set it to its parent handler so that it gets NOT (by Robert) printed on the server log
// In the original sample this is set to true
logger.setUseParentHandlers(false);
The actual way of adding your own file log handler:
// Create a file handler with a string as parameter for filename
Handler fh = new FileHandler(<LOGFILENAME>);
// Create a formatter to format the logger
fh.setFormatter(new SimpleFormatter());
// Add the handler to logger instance
logger.addHandler(fh);
See the javadocs for formatting stuff,
HTH Robert