users@glassfish.java.net

Re: Logging Question

From: <glassfish_at_javadesktop.org>
Date: Wed, 30 May 2007 15:24:42 PDT

Logging is already done to plain text files (check your domain directory for the logs directory -- that's where the default logs go). The console simply farms these files for its information.

Any of the common logging frameworks lets you do pretty much anything you want with logging, including directing a specific subset of the log to a different file. You'll need to look up the documentation on your specific framework to get the details about this.

You don't have any direct control over the logging for GF itself per se, save that you can adjust the logging levels using the Admin UI for the assorted components of the system. I do not know (I have not looked) whether the actual logging configuration parameters used by Glassfish are exposed anyplace convenient (in a file within the domain, perhaps). The actual values exposed by the UI are stored in the domain.xml, but that's a GF artifact rather than the actual configuration of the underlying logging system.

Glassfish happens to use the java.util.logging facility. There is a default logging properties file in the JRE for the Java logging facility, it's located in $JAVA_HOME/jre/lib/logging.properties, but it wouldn't surprise me at all if Glassfish completely ignored this file and simply internally configured the logger to its liking.

As for choosing a logger for your own system, all I can say is that I've stuck with the java.util.logging system for my apps. If you have no committment to either of the popular frameworks (notably log4j or java's), then, frankly, it's pretty much a wash as to which one you use. They're both pretty much equal I think. Log4j may have some more handlers to direct logging traffic vs java's, but I haven't looked in depth at this part as I'm happy with files for the time being.

log4j is popular among the open source packages, however, and minimally commons-logging tends to be layered upon that, so if you use a lot of OSS packages, you may end up getting log4j no matter what, so it could be used instead.

Either way, what I did do was write a simple wrapper to be more Java 5 friendly. Basically, to allow me to call log.debug(" the {0} in the {1}", "cat", "hat"). This is a MUCH nicer interface that java.util.logging lacks (and can't really fix for compatability reasons). But it's a trivial wrapper.

There are other logging APIs out there as well for Java, but I'm happy with Java's stock implementation.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=219551