users@glassfish.java.net

logger configuration in GFv2

From: Johnny Tolliver <jxt_at_ornl.gov>
Date: Thu, 27 Mar 2008 10:50:05 -0400 (EDT)

Until I switched to Glassfish, here's how I set up java.util.logging in my
web apps, slightly simplified for clarity. Notice that I remove all existing
handlers and then create my own and add it to the logger. So I expect to get
output from only one handler. I also use my own formatter to make it look
like I want.

    Logger logger = Logger.getLogger ("some.logger.path");
    Level finest = Level.parse ("FINEST"); // or whatever from init parameter
    logger.setLevel (finest);
    for (Handler handler : logger.getHandlers ()) {
        logger.removeHandler (handler);
    }
    Handler handler = new ConsoleHandler ();
    handler.setLevel (finest);
    handler.setFormatter (new MyFormatter ());
    logger.addHandler (handler);
    logger.finest ("test message");


This has always worked great in Tomcat. I get one line of output for each
log message because I'm using my own abbreviated formatter.

Then I switched to Glassfish. Unfortunately the same code doesn't seem to
get rid of some default handler. What I get in the log file now is TWO sets
of output for each log message, one formatted with my formatter added to the
end of some default handler's format and another with just the default
handler/formatter.

Here's an example, first the output that uses my own formatter, broken into
multiple lines for email purposes:

[#|2008-03-27T08:51:33.095-0400|WARNING|sun-appserver9.1|
javax.enterprise.system.stream.err|
_ThreadID=22;_ThreadName=httpSSLWorkerThread-8082-3;
_RequestID=ec5eae35-e725-40d8-a351-efbff630c3ad;|
MY MESSAGE HERE, FORMATTED WITH MY FORMATTER WHICH INCLUDES THE TIME (again)
AND CLASS AND METHOD NAMES|
#]


This is followed by the same log message using some default
handler/formatter:

[#|2008-03-27T08:51:33.095-0400|FINE|sun-appserver9.1|
gov.sensorpedia.rftrax.server|
_ThreadID=22;_ThreadName=httpSSLWorkerThread-8082-3;
ClassName=gov.sensorpedia.rftrax.server.RFTraxServlet;
MethodName=handle_login;
_RequestID=ec5eae35-e725-40d8-a351-efbff630c3ad;|
MY MESSAGE HERE|#]


It appears that my log messages are being handled by two different handlers
-- mine and some default. My question is twofold. First, why doesn't the
remove handler loop above remove that default message handler? Second, how
can I get this to work the way I want?

Thanks,
Johnny S. Tolliver
Oak Ridge National Laboratory
tolliverjs_at_ornl.gov, 865-574-1305