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]
# 1

Hi,

Although it is a while ago a worked with version 7, i kind of remember that the logging sample bundled with the appserver show how to log to the parent logger (system messages go there as well) or a application log.

Look at the samples under logger (there is only one i think.

HTH Robert

robert@javix at 2007-7-7 11:33:42 > top of Java-index,Application & Integration Servers,Application Servers...
# 2
And do you know where is logging sample bundled ?A lot of thanks
Grohl at 2007-7-7 11:33:42 > top of Java-index,Application & Integration Servers,Application Servers...
# 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

robert@javix at 2007-7-7 11:33:42 > top of Java-index,Application & Integration Servers,Application Servers...